2013-07-14 94 views
0

請幫助我。我需要使用.htaccess請求變量重寫URL

http://example.com/topusers.php?sort=post_count&time=month

改寫這個網址到這種風格

http://example.com/top/post_count/month

我在.htaccess中使用這個,但是當我參觀example.com/top,它顯示404未找到。

RewriteRule ^top/([^/.]+)?/?(.*)$ topusers.php?sort=$1&time=$2

它需要通過example.com/top可訪問過,因爲我設置的默認值,如果sorttime不通過URL設置。

謝謝。

回答

2

您需要在重寫規則中的top之後加斜線。

RewriteRule ^top/?([^/.]+)?/?(.*)$ topusers.php?sort=$1&time=$ 
+0

謝謝您的回答。如果我希望URL末尾的斜槓是可選的(URL有效或無效),我該如何改變RewriteRule? :) –

+0

見編輯answear –

+0

謝謝,但它不工作。是的,它是可訪問的,但是當我回顯變量時,結果是錯誤的。 示例鏈接:'topusers.php?sort = post&time = all', With'^ top /([*/.]+)?/?(.*)$ topusers.php?sort = $ 1&time = $ 2 ','sort ='post'','time ='all'' With'^ top /?([^/.]+)?/?(.*)$ topusers.php?sort = $ 1&time = $ 2','sort ='users'','time ='.php'' –