|
Home > Archive > Apache Server configuration support > March 2005 > Using Mod Rewrite to Switch the Document Root based on time
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using Mod Rewrite to Switch the Document Root based on time
|
|
| Matthew Deleon 2005-03-24, 5:53 pm |
| Hi everyone,
I have been trying to get to grips with the rewrite rules and I'm
finally having to ask for some help.
I am trying to switch the DocumentRoot for one domain name based on
what time of day it is. To be more specific at hours starting with an
odd number I want to go to one directory and if the time starts with
an even number to another directory. To make matters a little worse I
have a number of virtual host so it must only affect one domain name.
My mess so far
=============
RewriteCond %{HTTP_HOST} ^specific.domain.name.com.*
RewriteRule TIME_HOUR
DOCUMENT_ROOT /www/ht_docs/1/ [L]
Thanks in advance for your help.
Matt
| |
| Justin Koivisto 2005-03-24, 5:53 pm |
| Matthew Deleon wrote:
> Hi everyone,
>
> I have been trying to get to grips with the rewrite rules and I'm
> finally having to ask for some help.
>
> I am trying to switch the DocumentRoot for one domain name based on
> what time of day it is. To be more specific at hours starting with an
> odd number I want to go to one directory and if the time starts with
> an even number to another directory. To make matters a little worse I
> have a number of virtual host so it must only affect one domain name.
>
> My mess so far
> =============
> RewriteCond %{HTTP_HOST} ^specific.domain.name.com.*
> RewriteRule TIME_HOUR
> DOCUMENT_ROOT /www/ht_docs/1/ [L]
>
> Thanks in advance for your help.
That's not going to happen with mod_rewrite - at least I haven't found
out how. Instead, I used a server-side script (in php) to control which
files were used by setting the include_path based on the time, then
simply issued an "include 'index.html';" statement which pulled the file
from the correct directory because of the include path setting. Another
way of handling it could be to use RewriteRule to append a query string
based on the time as well. You may also want to try SetEnvIf and use
Apache's environment variables to do what you want... or maybe at system
level, a cron to gracefully restart apache every X hours and load a
different config file (PITA, I'm sure - not recommended).
IIRC can't use the RewriteCond to work with any other statement other
than RewriteRule.
--
Justin Koivisto - justin@koivi.com
http://koivi.com
| |
| Matthew Deleon 2005-03-25, 8:50 pm |
| Justin Koivisto <justin@koivi.com> wrote in message news:<WkD0e.566$q3.30877@news7.onvoy.net>...
> Matthew Deleon wrote:
>
>
> That's not going to happen with mod_rewrite - at least I haven't found
> out how. Instead, I used a server-side script (in php) to control which
> files were used by setting the include_path based on the time, then
> simply issued an "include 'index.html';" statement which pulled the file
> from the correct directory because of the include path setting. Another
> way of handling it could be to use RewriteRule to append a query string
> based on the time as well. You may also want to try SetEnvIf and use
> Apache's environment variables to do what you want... or maybe at system
> level, a cron to gracefully restart apache every X hours and load a
> different config file (PITA, I'm sure - not recommended).
>
> IIRC can't use the RewriteCond to work with any other statement other
> than RewriteRule.
This seems to work:
RewriteCond %{HTTP_HOST} mydomain\.tv
RewriteCond %{TIME_MIN} 1$|3$|5$|7$|9$
rewriteRule (\?*) http://www.otherdomain.co.uk/index.htm$1
RewriteCond %{HTTP_HOST} mydomain\.tv
RewriteCond %{TIME_MIN} 2$|4$|6$|8$|0$
rewriteRule (\?*) http://www.yetanotherdomain.tv/index.htm$1
However when I paste these lines from dev server running on apache
2.0.52 to our live server running 1.3.27 the code fails to work.
Can anyone shed any light on my mistake.
Thanks
Matt
|
|
|
|
|