Search code examples
apachemod-rewriteosx-server

Set alternate content until a specific date with Apache RewriteRule and RewriteCond


I need to serve an under construction page until a specific date, but I will be out of the country on the day the new content needs to display, and for a week and a half after (I know, first world problems...)

What I currently have serving the under_construction page in my httpd-vhosts.conf file.

RewriteRule ^(.*)$ \
http://localhost:8080/VirtualHostBase/\
http/%{SERVER_NAME}:80/under_construction/VirtualHostRoot$1 [L,P]

What I would like to use is below, but I don't fully understand how it should work, and of course it isn't working properly because it isn't configured properly. I have tried changing out the time string to get it to change a few minutes after the restart, but the configuration is probably not right to begin with.

RewriteRule ^(.*)$ \
RewriteCond ^{TIME} < 201304220000
http://localhost:8080/VirtualHostBase/\
http/%{SERVER_NAME}:80/under_construction/VirtualHostRoot$1 [L,P]

RewriteRule ^(.*)$ \
RewriteCond ^{TIME} > 201304220000
http://localhost:8080/VirtualHostBase/\
http/%{SERVER_NAME}:80/content/VirtualHostRoot$1 [L,P]

Am I at least on the right track? Also, besides localhost:80/server-status, is there any way to see the status of Apache (date, time, etc.), from Terminal for instance? Any help would be greatly appreciated!


Solution

  • Spaces are not allowed between the comparison operator and the CondPattern

    RewriteCond %{TIME} <20130422000000
    RewriteRule ^(.*)$ \
    http://localhost:8080/VirtualHostBase/\
    http/%{SERVER_NAME}:80/under_construction/VirtualHostRoot$1 [L,P]
    
    RewriteCond %{TIME} >=20130422000000
    RewriteRule ^(.*)$ \
    http://localhost:8080/VirtualHostBase/\
    http/%{SERVER_NAME}:80/content/VirtualHostRoot$1 [L,P]
    

    Also don't forget to use >= or <=, depending on whether you want to switch on that day or a day later.