2009-08-26 84 views
1

我有喜歡的網址 /?test,我想重寫/page.php?page=test.htaccess的查詢字符串改寫

我想這樣的,但由於某種原因,這是行不通的。

RewriteRule ^\?([a-z0-9\-\+]{3,20})/?$ /page.php?page=$1 [NC,QSA] 

我在做什麼錯?

回答

5

查詢字符串只能用RewriteCond directive進行測試。 RewriteRule模式僅針對URL path(在.htaccess文件中沒有每個目錄前綴的URL路徑)進行測試。

那麼試試這個:

RewriteCond %{QUERY_STRING} ^[a-z0-9-+]{3,20}$ [NC] 
RewriteRule ^$ /page.php?page=%0 [QSA] 
+0

我明白了。它幾乎工作,但查詢字符串頁面是空的,當我試圖讓它在page.php – Martin 2009-08-26 20:19:37

+0

@Martin:修復它。 – Gumbo 2009-08-26 20:30:25

+0

啊,作品,謝謝! – Martin 2009-08-27 06:47:29