r/ScriptSwap • • Jan 10 '13

[request] htaccess maintenance script

I'm wanting to write a script that will loop through each of my web roots, check for a .htaccess file AND a .htaccess_maintenance file.

  • This script will have a stdin variable of either "on" or "off".
  • If "on" it will find the production .htaccess rename it to .htaccess_live then rename .htaccess_maintenance to .htaccess.
  • If for some reason .htaccess_maintenance doesn't exist it'll create it then rename it to .htaccess
  • If for some reason the site doesn't have a live .htaccess file, it will only rename .htaccess_maintenance to .htaccess.

  • This will all reverse if stdin is "off"

Here's the caveat, I'm a noob at shell and perl scripting. I can read it and understand it 100%, but I just don't know enough to write from scratch. I would much rather write this script myself in either language than have someone write it for me.

My ultimate question is, how can you help me write this with specific examples or resources?

3 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/loganbest Jan 10 '13

I also went a slightly different approach. As you'll see in my previous comments I'm creating a ".maintenance_mode" file in each docroot.

This will require these lines to be in each .htaccess file in the docroot, which is better for me.

RewriteCond /var/www/sitedirectory/.maintenance_mode -f
RewriteRule (.*) maintenance.html [L]

The next step is to allow inputting a directory name to apply the maintenance mode to rather than all of them, but I can figure that out tomorrow. Thanks for your help!