2014-05-20 107 views
2

我想將所有請求重定向到index.php。mod_rewrite將所有請求重定向到index.php,包括目錄

如:localhost/abc/def --->localhost/index.php?url=abc/def

這裏是我的.htaccess線:

RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] 

但是我有一個問題,我有一個目錄 「測試」,當我去localhost/test,我希望它重定向到locahost/index.php?url=test,但地址欄顯示爲localhost/test/?url=test

如何刪除查詢字符串? (?url=test或類似的東西,當我輸入地址訪問目錄)?

+0

你試過:http://stackoverflow.com/questions/3800768/php-redirecting-all-pathes-to-a-certain- php文件? –

回答

3

這是因爲mod_dir在您的重寫規則之後運行並添加重定向以添加尾部斜線。

你可以在你的根的.htaccess有這樣的:

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*?)/?$ index.php?url=$1 [QSA,L] 

RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^(.+?)/$ index.php?url=$1 [QSA,L] 
+1

+1!我想知道爲什麼它似乎在做重寫和重定向! –

相關問題