2012-01-18 88 views
3

有人可以告訴我,我應該怎樣寫入我的.htaccess文件,以便'/ .php'替換爲'.php'。使用.htaccess爲網址添加'/'

我搜查了整個網絡,我真的找不到具體的答案。

另外,我想替換查詢字符串,如「?鍵1 =值&鍵2 =值」與「/?鍵1 /值1 /鍵2 /值2 /」

我已經花了我一整天尋找答案但找不到任何。

+0

所以你想[刪除PHP擴展](http://stackoverflow.com/questions/4588022/htaccess-to-remove-php-extension-godaddy)? – 2012-01-18 18:12:29

+0

是的,我需要.. – user1156837 2012-01-18 21:57:35

回答

1

對於查詢字符串,您可以使用這些規則來從您的查詢字符串替換&=

# replace all of the "=" 
RewriteCond %{QUERY_STRING} ^(.*)=(.*)$ 
RewriteRule ^(.*)$ /$1?%1/%2 [N] 

# replace all of the "&" 
RewriteCond %{QUERY_STRING} ^(.*)&(.*)$ 
RewriteRule ^(.*)$ /$1?%1/%2 [N] 

# ensure there's a trailing "/" at the end of the query string 
RewriteCond %{QUERY_STRING} !/$ 
RewriteRule ^(.*)$ /$1?%{QUERY_STRING}/ [N] 

這將需要請求:/something?a=b&c=d&e=f它改寫爲:/something?a/b/c/d/e/f/

+0

你錯過了用'/'取代'.php'擴展名。但我想在互聯網上已經有很多關於這個的帖子,比如你的輸入,真的很感激.. :) – user1156837 2012-01-18 21:55:31