0

I have to add a rule in a server that host many sites. This rule must be added only in those .htaccess files that belongs to a site with domain beggining with "dev-" or "review-".

I have this:

#!/bin/bash HOMEFOLDER=/home/* FILE='public_html/.htaccess' for f in $HOMEFOLDER; do # Only enter to folders if [ -d "$f" ] then cd "$f" echo ">>>> $f" then echo ".htaccess file not found!" else if grep -Fxq "# rule 01312019" $FILE then echo "Rule 01312019 already added!" else # Back up .htaccess TODAY=$(date +"%Y%m%d%H%M%S") echo "Back up .htaccess" mkdir -p backup # Save a timestamped copy in case of multiple script runs. cp $FILE backup/.htaccess.$TODAY # Same name copy for easy rollback. cp $FILE backup/.htaccess # Add rule 01312019 echo "Adding rule 01312019" echo "++++++" echo "# rule 01312019" >> $FILE echo 'SetEnvIf Host "^dev-|^review-" INTERNAL' >> $FILE echo "# set header only if internal domain" >> $FILE echo "Header set X-Robots-Tag "noindex, nofollow, noarchive" env=INTERNAL" >> $FILE fi fi echo "" fi done; 

I know the regular expression is not ok. I need the correct way to write it.

Thank you.

9
  • So, your question is about the BASH script, not .htaccess? Commented Feb 1, 2019 at 0:48
  • More about regular expressions to match urls in .htaccess. Commented Feb 1, 2019 at 0:56
  • I'm writing a bash script just because it's one server with multiple sites. Commented Feb 1, 2019 at 0:57
  • Is the relevant part of your script this line... SetEnvIf Host "^dev-|^review-" INTERNAL? Is that the regex you are asking about? But that regex looks OK (it could be "improved", but otherwise it's OK). (However, this isn't really what your question is asking? If it was then the "Bash" part of your question is seemingly irrelevant?) Commented Feb 1, 2019 at 1:07
  • 1
    You were right @MrWhite. I don't know the reason, but now the requests to the sites are responding with X-Robots-Tag Http Headers as expected. I think maybe it's something about permissions, because I did some changes related to that in a while, tired of trying. Thank you anyway. Commented Feb 4, 2019 at 20:58

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.