2009-12-13 33 views
0

我試圖在.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的文件?

+0

只是爲了澄清 - 這是一個內部無限遞歸誤差(導致在瀏覽器中看到500錯誤) - 而不是重定向循環(這將被瀏覽器報告)。 – fooquency 2009-12-13 23:51:59

回答

0

只排除要重定向到目的地,在這種情況下/path/to/stubfile.html

RewriteCond %{HTTP_HOST} ^thehost.example.com$ 
RewriteCond %{REQUEST_URI} !^/dont-rewrite-when-at-this-url 
RewriteCond %{REQUEST_URI} !=/path/to/stubfile.html 
RewriteRule ^(.*)(/|\.html|\.txt)$ /path/to/stubfile.html?/$1$2 [last,qsappend] 
+0

不是;正如我所說的,添加一個RewriteCond來豁免stubfile本身仍然會導致遞歸。無論如何感謝您的建議。 – fooquency 2009-12-13 23:44:41

+0

@fooquency:什麼是/ path/to/stubfile.html? URL路徑或文件系統路徑? – Gumbo 2009-12-13 23:59:13

+0

這是一個URL路徑。 – fooquency 2009-12-14 00:30:11

相關問題