2012-08-31 113 views
0

我有以下網址http://www.example.com/teams.php?team_id=12 我希望這個網址是http://www.example.com/teams-pavilion-boys-varsity-soccer隱藏PHP擴展使用的.htaccess URL重寫

我曾嘗試下面的代碼

Options +FollowSymlinks  
RewriteEngine on  
RewriteRule ^teams-([0-9a-zA-Z]+)\.html$ teams.php?team_id=$1 

請幫助我。

在此先感謝

+0

而不是「請幫助我」你可能已經解釋瞭如何的事情它行爲不端,或者你在絆腳石。 (猜測不完整的charclass /缺少url後綴,並期望從字符串中實現數字id。) – mario

+0

當您嘗試使用代碼時發生了什麼?換句話說,「什麼不工作」? – Havelock

+0

可能重複的[RewriteRule不會在.htaccess文件中工作](http://stackoverflow.com/questions/11354509/rewriterule-will-not-work-in-htaccess-file) – mario

回答

-1
RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} -f [OR] 

RewriteCond %{REQUEST_FILENAME} -d 

RewriteRule .* - [L] 

RewriteRule ^(.*)$ [URLHERE] [NC] 

WATCH THIS

0

檢查了這一點:

http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html

我建議經過team_name,而不是team_id或者你可以計算出從該team_name ID。我甚至可以通過在所有的你需要像'鎮'性別「排名」「運動」

RewriteEngine on 
RewriteRule ^teams-([a-zA-Z0-9_-]+)$ teams.php?team_name=$1 

或者

RewriteEngine on 
RewriteRule ^teams-([a-zA-Z0-9_-]+)-([a-zA-Z0-9_-]+)-([a-zA-Z0-9_-]+)-([a-zA-Z0-9_-]+)$ teams.php?team_town=$1&team_gender=$2&team_rank=$3