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.
.htaccess
?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?)