我試圖在.htaccess文件中重寫工作,即使存在與請求的URL相同位置的文件也是如此。即使存在相同URL的文件,也要執行重寫(不會出現錯誤500:無限遞歸)
即我想重寫/about/index.html即使在/about/index.html處有文件也會發生。
目前我有:
RewriteEngine On
RewriteBase/
RewriteCond %{HTTP_HOST} ^thehost.example.com$
RewriteCond %{REQUEST_URI} !^/dont-rewrite-when-at-this-url
RewriteRule ^(.*)(/|\.html|\.txt)$ /path/to/stubfile.html?/$1$2 [last,qsappend]
的問題是,如果我要求
http://thehost.example.com/about/index.html
,並在/about/index.html文件是否存在(這是我想要的,即重寫應該發生,如果文件確實存在,雖然它也可能會發生,如果它沒有)
然後我得到錯誤500:無限遞歸。
(添加的RewriteCond免除自身被改寫沒有區別stubfile。)
htaccess rewrite causes 500 error instead of 404表明,沒有-f的RewriteCond的防止遞歸,但隨後的結果的行爲,我想不會發生。
有沒有辦法讓重寫發生,即忽略文件存在的事實,只要重寫即使存在相同URL的文件?
只是爲了澄清 - 這是一個內部無限遞歸誤差(導致在瀏覽器中看到500錯誤) - 而不是重定向循環(這將被瀏覽器報告)。 – fooquency 2009-12-13 23:51:59