apache - .htaccess 重定向到目录中的文件

标签 apache .htaccess http redirect mod-rewrite

网站将很快停止维护。与此同时,所有访问者都将被重定向到一个页面,该页面指示该网站将在短时间内关闭,直到维护完成。

如果我想将所有与我的 IP 不匹配的流量重定向到位于 maintenance 目录中的此页面

https://example.com/maintenance/index.php

这些重写规则是否有效和/或对我想要完成的工作有效?

RewriteCond %{REQUEST_URI} !/maintenance/index.php$ 
RewriteCond %{REMOTE_ADDR} !^192\.192\.192\.192$
RewriteRule $ /maintenance/index.php [R=302,L]

最佳答案

在 .htaccess 中执行此操作

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /maintenance/index.php [L,QSA]

任何访问您网站上某些链接的人都将被重定向到:

www.yourwebsite.extension/maintenance/index.php

关于apache - .htaccess 重定向到目录中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53918239/

相关文章:

css - 允许其他人更改 iframe 中内容的 css

apache - 如果 REQUEST_URI 以某些内容开头则重定向

从 Apache 运行的 PHP 无法写入文件系统

PHP 停止与 Apache 合作

apache - 不小心删除了/etc/apache2/文件夹,怎么办?

angularjs - 如何为 angularjs 网站做 301 重定向

apache - 删除所有子文件夹条件重写.htaccess Apache 1.3.42

java - Jackson 反序列化 - 空对象引用上的 JsonMappingException

json - 需要将 POST 重定向到对另一个域的 API 调用

.htaccess - 如何使用 .htaccess 将所有流量 302 重定向到主页?避免无限重定向循环?