0

我的 .htaccess 文件中有一个 mod 重写,其中包含几个重写条目:

RewriteRule ^/services/(\w+)$ controllers/$1.php [L]
RewriteRule ^.*$ index.html [L]

每当我访问http://blah.com/services/something时,它都会将我重定向到 blah.com 的索引,而不是匹配第一条规则然后停止。

另外:如果我将最后一条规则更改为:

RewriteRule ^(\w+)$ index.html [L]

应用程序“有效”,只是在第一个 / 之后有其他路径时无效。

为什么会这样?

4

1 回答 1

0

此规则 ( RewriteRule ^.*$ index.html [L]) 过于通用,当从 htaccess 文件调用时,会将所有内容重写到您的索引页面。在从 services/something 重定向到 services/controller/something.php 之后,再次调用根 htaccess,第一个规则不适用(没有匹配),所以它转到匹配的第二个。

我能想到 3 件事可能会有所帮助:

1)您是否尝试过使用 END 标志?

RewriteRule ^/services/(\w+)$ controllers/$1.php [END]

2)在您的services/controller目录中放置一个会使您的根级别htaccess无效的htaccess。例如使用指令RewriteEngine off

3) 通过使用 RewriteCond 指令列表,使您的重定向到索引规则更加具体。

于 2013-11-03T14:17:12.583 回答