2012-09-08 64 views
1

我很困惑我的重寫規則的結果。我使用WAMP託管在本地機器上。奇怪的重寫(Apache mod_rewrite)

RewriteEngine on 
RewriteBase /niklasrosenstein/ 

RewriteCond %{REQUEST_URI} !res/(.+)$ 
RewriteCond %{REQUEST_URI} !index.php$ 
RewriteRule ^(.*)$   index.php?uri=$1 [QSA] 

http://localhost/niklasrosenstein/res

擴展到

http://localhost/niklasrosenstein/res/?uri=res

瀏覽器'地址欄中。我已經火狐14,歌劇11.62和Internet Explorer 8

下測試它添加在URL的末尾斜線,這將是

http://localhost/niklasrosenstein/res/

是確定的。

有誰知道爲什麼在瀏覽器的地址欄中調整URL?我想用mod_rewrite的爲了擺脫模糊URL格式的,但這個問題實際上打破它下來..

回答

2

有誰知道爲什麼網址在瀏覽器的地址欄中調整?

這看起來像是mod_dir/mod_rewrite衝突。默認情況下,mod_dir被加載,而目錄模塊的默認值有:

DirectoryIndex index.html 
DirectorySlash On 

第二默認使得它如此隨時隨地的請求似乎訪問目錄,並且缺少結尾的斜線,301重定向到同一帶斜線的URI。這發生在某處URI文件映射管道,並與內部重寫interferring是mod_rewrite是通過你的規則適用

既然你是通過index.php路由的一切,也未必detrimental to turn off DirectorySlash,所以在htaccess的文件在您/niklasrosenstein/目錄,試圖將其關閉:

DirectorySlash Off 

否則,你可以嘗試處理那些使用mod_rewrite:

RewriteCond %{REQUEST_FILENAME} -d 
RewriteCond !.+[^/]$ 
RewriteRule ^(.+)$ $1/ [L]