2011-10-18 25 views
0

HIII,定期htaccess的URL重寫表達

我想重寫目錄www.mysite.com/index.php?category=news 到www.mysite.com/news 我寫這篇文章的代碼,但其不工作 任何人都可以幫助,請 感謝您的幫助

RewriteEngine On  
RewriteRule ^([a-zA-Z0-9-/]+)$ index.php?category=$1 

感謝所有誰回答我的問題,所有的代碼都工作時,我嘗試寫www.mysite.com/news,但我的意思是當我點擊鏈接 「a href ='index.php?category = news'」link「/ a」我想成爲r馬上寫入www.mysite.com/news

+0

會發生什麼事,當你去http://www.mysite.com/news? –

+0

我相當肯定你的意思是「重寫'news'到'index.php?category = news'」而不是其他方式 – Phil

+0

levi Morrison,它的作品,但我的意思是當我點擊一個鏈接「a href =' index.php?category = news'「link」/ a「我想立即改寫爲www.mysite.com/news –

回答

1

只是要確認,你想匹配的模式是所有的字母,數字,連字符和正斜槓,對不對?

如果是的話,試試這個

RewriteRule ^([a-zA-Z0-9/-]+)$ index.php?category=$1 [QSA,L] 

我認爲這個問題可能是你在字符類表達式連字符和正斜槓進行排序。要匹配連字符,它們應該出現在字符集中的第一個或最後一個。

0

這是行不通的?

RewriteBase/
RewriteRule (.*) index.php?category=$1 [QSA,NC,L] 
0

試試這個

Options +FollowSymLinks 
RewriteEngine on 
RewriteRule news/ index.php?category=news 
RewriteRule news index.php?category=news 
0
RewriteRule ^(news|or|some|other|category)$ index.php?category=$1 [QSA,NC,L]