我的文件夹结构如下所示:重写规则导致无限重定向循环
/var/www/.htaccess
/var/www/site/index.php
/var/www/site/images/test.png
凡.htaccess
文件看起来像这样:
RewriteEngine On
RewriteCond /site/%{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ /site/%{REQUEST_FILENAME} [L]
RewriteRule ^(.*)$ /site/index.php [L,QSA]
从本质上讲,我想所有的URL重写到/网站/目录中,并将现有文件简单地重写为其在site
文件夹中的路径,同时使不存在的任何文件重写为/site/index.php
。
的.htaccess
文件上面/images/test.png
作品,但对于/
它会导致一个无限循环,据报道在Apache的错误日志:
[Sat Jun 13 21:42:04.003016 2015] [core:error] [pid 12949] [client 127.0.0.1:50560] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Sat Jun 13 21:42:04.003020 2015] [core:debug] [pid 12949] core.c(3533): [client 127.0.0.1:50560] AH00121: r->uri = /site/index.php
[Sat Jun 13 21:42:04.003022 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] AH00122: redirected from r->uri = /site/index.php
[Sat Jun 13 21:42:04.003033 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] AH00122: redirected from r->uri = /site/index.php
[Sat Jun 13 21:42:04.003035 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] AH00122: redirected from r->uri = /site/index.php
[Sat Jun 13 21:42:04.003037 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] AH00122: redirected from r->uri = /site/index.php
[Sat Jun 13 21:42:04.003038 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] AH00122: redirected from r->uri = /site/index.php
[Sat Jun 13 21:42:04.003040 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] AH00122: redirected from r->uri = /site/index.php
[Sat Jun 13 21:42:04.003041 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] AH00122: redirected from r->uri = /site/index.php
[Sat Jun 13 21:42:04.003048 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] AH00122: redirected from r->uri = /site/index.php
[Sat Jun 13 21:42:04.003049 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] AH00122: redirected from r->uri = /site/index.php
[Sat Jun 13 21:42:04.003050 2015] [core:debug] [pid 12949] core.c(3540): [client 127.0.0.1:50560] AH00122: redirected from r->uri =/
根据该文件,重写规则可能,如果他们”重新运行重新在.htaccess
文件出于各种原因,但我不知道为什么,或如何防范它。我尝试在第二个RewriteRule
之前添加一个RewriteCond
,以便只在文件名不是/site/index.php的情况下运行规则,但会导致所有URL(甚至现有文件)重写为/site/index.php。
要论正是我想要的,我想下面的URI改写为以下路径更加清晰:
/
- >/site/index.php
/test
- >/site/index.php
/images/test.png
- >/site/images/test.png
(因为文件存在)/images/bla.png
- >/site/index.php
(因为文件不存在)
我已经更新的问题更清楚一点。 – Codecat
@AngeloGeels我也是这样回答:) – splash58
谢谢,这个解决了! – Codecat