我正在寻找一个脚本,可以将网站的所有页面重定向到一个页面,说明整个网站因宗教原因在周日关闭。
它应该只在周日重定向。在一周的所有其他日子里,该网站应正常运行。
我想在服务器级别的 .htaccess
文件或 PHP 脚本中执行此操作。
我可以想象这样的事情:
$day = date('w');
if ($day == 0) { // Sunday...
header("Location: http://www.domain.com/closedonsunday.html");
}
最佳答案
您可以在 .htaccess
中使用以下规则:
RewriteEngine on
#--if WDAY ==0--#
RewriteCond %{TIME_WDAY} 0
#--redirect the domain to /closedonsunday.html--#
RewriteRule ^((?!closedonsunday\.html).*)$ /closedonsunday.html [L,R]
%{TIME_WDAY}
变量表示星期几 (0-6)。
如果满足条件,上面的代码会将所有请求重定向到 /closedonsunday.html
。
关于php - 我怎样才能 "close"网站只在星期天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35864344/