【发布时间】:2016-10-07 13:33:28
【问题描述】:
我需要站点上的每个页面请求(200、404 等)都到达站点上的固定页面,在本例中为 index_new.php。
我已经尝试了其他 SO 和 ServerFault 答案,但我继续得到一个无休止的重定向循环。
这是我在 httpd.conf 中的代码:
<VirtualHost *:80>
ServerName my.example.com
ServerAlias *.my.example.com
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index_new.php
RewriteRule ^(.*)$ /index_new.php [R=301,L]
</VirtualHost>
注意事项:
- 网站的
.htaccess文件为空 - “
index_new.php”页面是静态的,没有 PHP 标头(“location:”)内部重定向等。 - 我已经重启了apache
【问题讨论】:
-
规则看起来不错,您可以省略 RewriteCond 并将其缩短为
RewriteRule !^/index_new.php$ /index_new.php [R,L]。切勿使用 R=301 进行测试 -
感谢@OlafDietsche。但是您的回答仍然会在我的 Chrome 浏览器中显示
my.example.com redirected you too many times.(并不是说浏览器与它有任何关系——只是向您显示结果消息的格式)。 -
我刚刚在本地尝试过,您的版本和我的版本都可以正常工作。也许还有别的东西。
-
好的,谢谢@OlafDietsche。我去看看。
-
我认为问题在于
<link>容器中有一个 css 样式表<link>'d。一旦我RewriteCond'd 了,我就可以走了。
标签: apache .htaccess redirect httpd.conf