无法在htaccess中重写到/index.php

时间:2013-12-03 02:32:19

标签: .htaccess mamp

这令我感到困惑。 这是我的htaccess代码

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^/rsrc/(.*)     -                       [L,QSA]
    RewriteRule ^/favicon.ico   -                       [L,QSA]
    RewriteRule ^(.*)$          /index.php?__path__=$0  [B,L,QSA]
</ifModule>

这给了我500服务器错误。但是,如果我从“/index.php?__ pat ......”中删除“/” 它的工作原理

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^/rsrc/(.*)     -                       [L,QSA]
    RewriteRule ^/favicon.ico   -                       [L,QSA]
    RewriteRule ^(.*)$          index.php?__path__=$0  [B,L,QSA]
</ifModule>

这是一个问题,因为我正在尝试设置的 thing 要求我使用斜杠。 我正在使用最新版本的MAMP。

1 个答案:

答案 0 :(得分:0)

这是因为你的规则是循环的。重写引擎继续运行所有规则,直到URI停止更改,并且您的模式(.*)匹配/index.php,因此规则不断应用。您可以尝试在最后一条规则中添加几个条件以防止循环:

RewriteCond %{REQUEST_URI} !index\.php
RewriteRule ^(.*)$          index.php?__path__=$0  [B,L,QSA]

或者

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$          index.php?__path__=$0  [B,L,QSA]
相关问题