【问题标题】:Redirect visitors from my website to other wesbsite using htaccess only by time [closed]仅按时间使用 htaccess 将访问者从我的网站重定向到其他网站 [关闭]
【发布时间】:2016-08-05 05:12:34
【问题描述】:

我需要根据时间将我的网站访问者重定向到另一个网站。 例如,在 00:00 到 10:00 之间访问我网站的任何访问者都将重定向到 xxx.com,而在 10:00 到 15:00 之间的访问者将重定向到 yyy.com

我需要使用 htaccess 而不是 php 来做到这一点

【问题讨论】:

  • 那么,您是否知道 Apache 中有任何时间操作函数,或者您只是希望它们存在?
  • 到目前为止你尝试过什么,我看不到要复制和粘贴的内容。我最好希望你不要重定向到 xxx.com
  • @Xorifelse ssshh,让 OP 来回答 :)
  • 如果您向我们提供有关您尝试过的内容的信息并希望提供支持代码示例,则此站点效果最佳,到目前为止,您似乎什么都没尝试过。为什么你受限于 htaccess?
  • 问题是我使用的托管服务限制我每天只能接收 5000 名访问者访问我的网站,但是为了避免在 5000 名访问者之后网站暂停,我收到了 4000 名访问者,然后我使用 htaccess 访问手动将访问者发送到另一个网站(不计算通过 htaccess 重定向的访问)@Scuzzy

标签: php apache .htaccess redirect


【解决方案1】:

您可以在“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.

【讨论】:

  • 那么如何将所有网站流量重定向到另一个外部页面?
猜你喜欢
  • 1970-01-01
  • 2018-08-13
  • 2017-04-30
  • 2019-12-31
  • 1970-01-01
  • 2013-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多