I have limited experience with Apache and even less with RewriteRules. I hope that someone can point me in the right direction on this.
Every morning, there are some scheduled tasks that execute on our server between 5:00 and 5:30am. During this time, we want to reroute web requests to an “under maintenance” page. I thought that using the htaccess page made a lot of sense because it would allow me to point the requests to a generic page without having to maintain a lot of setting changes. My question has two parts:
- Is a RewriteCond statement in the htaccess file compared with the current time/date the best way to go for this?
- Can the rule be written to prevent the direct access of a page (i.e. index.htm)? If so, can this be specified for all subfolders too?
Given that the RewriteCond TIME variable presents itself as “yyyymmddhhnnss” I’m assuming it will look something like this:
RewriteCond %{TIME} ^(([0-9]{8})[0][5][0-2][0-9][0-5][0-9])
RewriteRule .* http://mysite.com/under_maintenance.htm
Does this make sense at all? I thank you for any and all assistance you can provide.
Thanks!
Craig
If you want this to happen automatically, you can match specifically against the
%{TIME_HOUR}and%{TIME_MIN}vars:This 302 (temporary) redirects to
http://mysite.com/under_maintenance.htmfor every request except the maintenance page. So the answer to:RewriteCondto compare to the time, it’s a good way to automate this without having to do anything extra.This rule will prevent access to everything except the maintenance page. You can vary this by adding additional conditions before the
RewriteRule, for example, if you want to allow/special_page.htm, then you’d add:and if you want to allow all iamges and css, then you’d add: