首页 > 解决方案 > 重定向每个页面,无论嵌套多深到同一域上的单个页面

问题描述

我已经看到了几个答案,但它们似乎都不适用于子目录或嵌套 URL。

基本上,我想将域上的所有内容重定向到同一个域上的“站点关闭”或“维护”页面,无论是使用直接 URL 还是目录指定,无论嵌套多深。

例如,所有这些:

example.com
example.com/page.html
example.com/sub
example.com/sub/page.html
example.com/sub/sub2
example.com/sub/sub2/page.html

...应该重定向到https://example.com/index_closed.html

我可以让它在 example.com 上工作,但不能在嵌套目录上工作。

此外,如果可能,它不应该重定向 .css 文件。谢谢!

标签: apacheredirect

解决方案


我发现以下工作:

RewriteCond %{REQUEST_URI} !/index_closed.html$ 
RewriteCond %{REQUEST_URI} !.css$ [NC]
RewriteCond %{REQUEST_URI} !.jpg$ [NC]
RewriteRule $ /index_closed.html [R=302,L]

推荐阅读