2012-03-21 86 views
4

如何使用.htaccess從http://domain.com/recent?page=2(原始頁面爲http://domain.com/?id=recent&page=2)取頁面變量? (我需要的所有網頁的一般規則)的幫助感謝名單.htaccess適用於所有分頁的通用規則

+0

你需要做什麼與該頁面var? – anubhava 2012-03-21 13:33:59

+0

用於分頁 – 2012-03-21 13:58:08

+0

我使用.htaccess(RewriteRule ^([^ /] +)$ index.php?id = $ 1)生成該頁面:http://domain.com/recent(原始http:// domain。 com /?id = recent)http://domain.com/recent?page=2是最近的第二頁 – 2012-03-21 14:08:23

回答

3

你重寫規則更改爲這樣的:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^([^/]+)/?$ index.php?id=$1 [L,QSA] 

關鍵的變化是使用QSA標誌甚至加入id=$1後,將保留原始查詢字符串。

+0

工程!謝謝! – 2012-03-21 15:01:36

1

這件事情就像

RewriteRule (.+)?page=([0-9]+) ?id=$1&page=$2 

看看正則表達式,你可以找到關於谷歌的例子;)

+0

由於QUERY_STRING在RewriteRule中不可用,因此不起作用。 – anubhava 2012-03-21 13:32:58

+0

真的。所以他需要有一個像近期2,而不是最近?page = 2的網址。 編輯:也許有一些與[querystrings](http://fantomaster.com/faarticles/rewritingurls.txt):RewriteCond%{QUERY_STRING} page =(。+) – NeeL 2012-03-21 13:52:15