我需要在托管多个网站的服务器中添加一条规则。此规则必须仅添加到域名以“dev-”或“review-”开头的网站所属的 .htaccess 文件中。
我有这个:
#!/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;
我知道正则表达式不行。我需要正确的书写方式。
谢谢。