2012-06-10 31 views
0

可能重複:
Query Strings & Mod ReWrite爲什麼心不是我的國防部重寫我的分頁工作

我寫了一個.htaccess文件,其正確地轉換以下行

http://localhost/questions/32/new-question-from-peter 

分成

http://localhost/questions.php?question_id=32. 



我使用的代碼是

RewriteRule ^questions/([0-9]+)/[^/]*(?:\?(.+)=(.*))?$ public/questions.php?question_id=$1&$2=$3 [NC,L] 


但是,當是以下URL,

http://localhost/questions/32/new-question-from-peter?page= <int> 

它不會正確處理網頁信息,即使當我的網址是

http://localhost/questions.php?question_id=32&page=2 

它完美的工作。

有人可以幫助我這個請,凡在我的代碼我已走了錯

回答

1

您應該使用QSA(查詢字符串附加)標誌,就像這樣:

RewriteRule ^questions/([0-9]+)/[^/]*/?$ public/questions.php?question_id=$1 [NC,L,QSA] 

查詢字符串(&page=2)是漢在這種情況下會自動調用,所以您不需要在正則表達式中處理它,並將其添加到重寫的URL的末尾。

+0

非常感謝,節省了我的大量時間 – yehuda

+0

沒問題。不要忘記接受最能幫助你的答案。 – Bojangles

+0

當我可以:-)我喜歡被接受呢! – yehuda

1

調試mod_rewrite的好,一般的辦法是建立一個日誌文件,並檢查發生的事情,所以重寫期間:

<IfModule mod_rewrite.c> 
RewriteLog "/var/log/rewrite.log" 
RewriteLogLevel 3 
</IfModule> 
+0

會檢查出來,謝謝! – yehuda