我需要根据时间将我的网站访问者重定向到其他网站。 对于00:00至10:00之间的任何访问,我的wbsite的任何访问者都将重定向到xxx.com,并且从10:00到15:00访问者的所有访问者将重定向到yyy.com
我需要使用htaccess而不是php
来做到这一点答案 0 :(得分:0)
您可以在" RewriteCond"中使用%{TIME_HOUR}
规则...
取自https://httpd.apache.org/docs/trunk/rewrite/advanced.html#time-dependent
说明
We wish to use mod_rewrite to serve different content based on the time of day.
解决方案:
There are a lot of variables named TIME_xxx for rewrite conditions. In conjunction with the special lexicographic comparison patterns <STRING, >STRING and =STRING we can do time-dependent redirects: RewriteEngine on RewriteCond "%{TIME_HOUR}%{TIME_MIN}" >0700 RewriteCond "%{TIME_HOUR}%{TIME_MIN}" <1900 RewriteRule "^foo\.html$" "foo.day.html" [L] RewriteRule "^foo\.html$" "foo.night.html" This provides the content of foo.day.html under the URL foo.html from 07:01-18:59 and at the remaining time the contents of foo.night.html.