'Create missing .htaccess file in wordpress and add the default wordpress .htaccess rewrite rule in it

I am stuck in a difficult situation here

I have hundreds of addon and subdomains under my "public_html" having WordPress instances inside them. While cleaning up the malware, I have removed the .htaccess files from these several WordPress instances.

now, I am looking for some help here to add back the default .htaccess file and its code for such WordPress instances in one command

is that possible?



Solution 1:[1]

Put the default .htaccess file into ~/public_html/default.htaccess and then use this script to copy it into any WordPress subdirectory that doesn't have a .htaccess file already:

cd ~/public_html
for dir in `ls -F | grep /`
do
  if [ ! -e "$dir/.htaccess" ] && [ -e "$dir/wp-config.php" ]
  then
    cp -v default.htaccess "$dir/.htaccess"
  fi
done

It could even be run as a one-liner:

cd ~/public_html; for dir in `ls -F | grep /`; do if [ ! -e "$dir/.htaccess" ] && [ -e "$dir/wp-config.php" ]; then cp -v default.htaccess "$dir/.htaccess"; fi; done

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1