我的文件夾結構如下所示:重寫規則導致無限重定向循環
/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