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

StackOverflow https://stackoverflow.com/questions/16057024

  •  04-04-2022
  •  | 
  •  

Question

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!

Était-ce utile?

La 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.

Autres conseils

You need the RewriteCond before the rule that it is applied to:

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]

The %{TIME} variable is the 4 digit year, 2 digit month, 2 digit date, 2 digit hour, 2 digit minute, and 2 digit second.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top