2012-08-16 47 views
0

我的.htaccess不重寫乾淨的URL就像我想要的。它沒有按照指示去做,它給了我一個404錯誤!.htaccess將不會根據需要重寫

我想這一點:

http://localhost/somepossiblepath 

被路由到這一點:

http://localhost/index.php?route=somepossiblepath 

目前,這是我的htaccess文件:

RewriteEngine On 

RewriteCond ${REQUEST_FILENAME} !-d 
RewriteCond ${REQUEST_FILENAME} !-f 
RewriteCond ${REQUEST_FILENAME} !-l 

RewriteRule ^/(.+)$ /index.php?route=$1 [QSA,L] 

我有一個當前的腳本測試看看它會不會起作用:

<?php echo $_REQUEST['route'] ?> 

當我輸入/index時,它將起作用,但當我輸入其他內容時不起作用。

任何幫助?

回答

0

在.htaccess文件中,通過規則正則表達式匹配的字符串的基目錄被剝離(/DOCROOT/.htaccess的情況下)。所以^/(.*)$將不匹配。你需要什麼,例如:

RewriteEngine On 

RewriteRule ^index\.php - [L] 

RewriteCond ${REQUEST_FILENAME} !-d 
RewriteCond ${REQUEST_FILENAME} !-f 
RewriteCond ${REQUEST_FILENAME} !-l 

RewriteRule ^(.+)$ /index.php?route=$1 [QSA,L] 
+0

你需要做的不僅僅是給一個禿頭的答案。 @nonplus可能甚至不會注意到你已經放棄了領先的'/'。我編輯了你的答案,以表明我的意思。 – TerryE 2012-08-16 17:33:55

+0

仍然不會工作:( – snnth 2012-08-18 00:05:43

+0

需要更多信息。 404錯誤或任何錯誤。 – user1603541 2012-08-18 06:35:59