Url 重定向到同一站点上的另一个页面

5 mod-rewrite apache-2.2

基本上我想将所有请求重定向到我的域到特定页面。例如,将所有请求重定向到页面 X,除非您已经在页面 X 上,在这种情况下,您应该只加载它。但我的解决方案只是创建了一个无限循环:/

我试过...

RewriteCond %{REQUEST_URI} !=/underconstruction.html
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !^/underconstruction.html
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Run Code Online (Sandbox Code Playgroud)

Tom*_*meh 12

上面例子的问题在于 RewriteRule 行没有重定向到 underconstruction.html,它们再次重定向到大致相同的 URL(因为 $1 匹配 (.*))。

此示例将 301 将所有 URL 重定向到“/underconstruction.html”:

RewriteEngine On
RewriteCond %{REQUEST_URI} !=/underconstruction.html
RewriteRule ^ /underconstruction.html [R=301]
Run Code Online (Sandbox Code Playgroud)

(翻译为“如果 URI 不是 /underconstruction.html,则重定向到 /underconstruction.html”)


fre*_*eit 1

根据您的描述,您想要一个更像这样的重写规则:

RewriteRule ^(.*)$ $LINK [L,R=301]
Run Code Online (Sandbox Code Playgroud)

换句话说,损失了 1 美元。这会将原始 URL 附加到新 URL,从而导致无限循环。

(我没有验证条件,但我认为其中之一应该有效)