不知道为什么这不起作用:
RewriteEngine On
RewriteCond %{HTTP_HOST} example.com$ [NC]
RewriteRule ^.+ http://example.com [L]
RewriteCond
据我所知,正在工作。对我来说,
RewriteRule
读到:^
开始比赛 .+
一个或多个字符 然而,Firefox 44 告诉我
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
如果
RewriteRule
开始于 ^.*
,我希望服务器陷入无限循环。但是
^.+
应该工作,不是吗?
最佳答案
由于 DirectoryIndex
,您正在接收重定向循环在 REQUEST_URI 中添加处理程序。
要解决此问题,您可以使用以下规则:
RewriteCond %{HTTP_HOST} www.localhost$ [NC]
RewriteCond %{REQUEST_URI} !^/index\. [NC]
RewriteRule ^.+ http://www.localhost [L,R]
RewriteCond %{REQUEST_URI} !^/index\. [NC]
将停止重定向循环,因为 /index.html
或 /index.php
通常是 DirectoryIndex
处理程序。
关于apache - 简单的 .htaccess RewriteRule 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35295647/