stardothosting.com initially created this script for just 1 dynamic IP and can be seen at this URL:

https://www.stackstar.com/blog/2012/05/add-your-dynamic-ips-to-apache-htaccess-files/

I modified their script to meet my needs:

  • Multiple dynamic IPs
  • Allow “allow from xxx.xxx.xxx.xxx” to be inserted into a pre-existing htaccess configuration

 

To start, you MUST first manually enter the <Files wp-login.php> section into your htaccess file BEFORE first use. If your htaccess file already has this section, then lines 1 & 2 MUST start the section. Lines 3 & 4 can dynamically move down if you have your own wp-login.php configurations that you need to maintain; in other words, add your configuration data between lines 2 & 3. Note: Once you enter this section and save the htaccess file, you WILL NOT BE ABLE to access your WordPress site until your cron job is first run.

 

The cron entry setup is just like stardothosting.com’s setup:

*/15 * * * * /bin/sh /usr/local/bin/HTAccessWithMultipleDynamicIPs.sh yourhostname1.dyndns.org /var/www/website.com/public_html/.htaccess > /dev/null 2>&1

You may create multiple cron jobs for multiple dynamic DNS names:

*/15 * * * * /bin/sh /usr/local/bin/HTAccessWithMultipleDynamicIPs.sh yourhostname2.dyndns.org /var/www/website.com/public_html/.htaccess > /dev/null 2>&1

*/15 * * * * /bin/sh /usr/local/bin/HTAccessWithMultipleDynamicIPs.sh yourhostname3.dyndns.org /var/www/website.com/public_html/.htaccess > /dev/null 2>&1

And so forth…

 

And now the script: