php - 我怎样才能 "close"网站只在星期天

标签 php .htaccess redirect

我正在寻找一个脚本,可以将网站的所有页面重定向到一个页面,说明整个网站因宗教原因在周日关闭。

它应该只在周日重定向。在一周的所有其他日子里,该网站应正常运行。

我想在服务器级别的 .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/

相关文章:

php - 将页面重定向到根目录,但保留 URL 中的参数

python - Flask:NameError:未定义全局名称 'redirect'

php - 当用户中止连接时回滚事务

content-type - 发送包含长 http 链接的 PHP mail() 时,我应该使用什么 Content-Transfer-Encoding?

php - Resteasy 服务需要 2 个 json 对象

apache - 使用 .htaccess 重写服务器特定 URL 的方法不遵守 RewriteCond

html - 文件夹中的 Apache htaccess : Block direct access to index. html

linux c/c++ 编程 telnet 连接 io 重定向

javascript - Angularjs 自动前缀正斜杠

php - 使用 Elastica 库删除 ElasticSearch 中的文档