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

不想你离开。 提交于 2019-12-25 02:06:23

问题


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!


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/16057024/set-alternate-content-until-a-specific-date-with-apache-rewriterule-and-rewritec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!