2011-12-30 44 views
0

嘿我已經有相當多的重寫工作的一個項目,但現在我想能夠通過附加參數主要接入點htaccess的,抓住更多的參數,並將其傳遞到重定向點

我htaccess的是:

Options +FollowSymlinks 
RewriteEngine on 
RewriteBase/
RewriteRule ^$      index.php [L] 
RewriteCond %{REQUEST_FILENAME}  !-f 
RewriteCond %{REQUEST_FILENAME}  !-d 
RewriteRule ^([^/]+)/?([^/]*)/?/?([^/]*)/?([^/]*)/?([^/]*)/?([^/]*)$ index.php?account=$1&task=$2&object_id=$3&app_type=$4&p=$5&items=$6 

我想什麼是能夠通過額外的參數和這些參數應rewrited並通過除原有的參數,如到index.php中:

http://site.com/user/books/434?another_param=8989898 

而且應該重寫相應的index.php爲:

index.php?account=user&task=books&object_id=434&app_type=&p=&items=&another_param=8989898 

必須我做什麼修改,以重寫這些額外的參數,並將其追加到原來的重定向爲.htaccess正在取得?

在此先感謝。

+1

勞倫斯Cherone只是說了出來。如果您需要更多信息,請查閱文檔http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteflags – craniumonempty 2011-12-30 12:01:27

回答

1

死的簡單,添加 「查詢字符串,附加」 標誌的重寫規則,格式爲:

RewriteRule Pattern Substitution [flags] 

(源)http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

的查詢字符串追加標誌僅僅是QSA,所以在您的例子中,你將有:

RewriteRule ^([^/]+)/?([^/]*)/?/?([^/]*)/?([^/]*)/?([^/]*)/?([^/]*)$ index.php?account=$1&task=$2&object_id=$3&app_type=$4&p=$5&items=$6 [QSA] 

你另一個有用的標誌是大號這意味着「最後」,即阿帕奇停止它進行替換後尋找更多的比賽:

RewriteRule ^([^/]+)/?([^/]*)/?/?([^/]*)/?([^/]*)/?([^/]*)/?([^/]*)$ index.php?account=$1&task=$2&object_id=$3&app_type=$4&p=$5&items=$6 [QSA,L] 
1

您需要添加QueryStringAppend [QSA]標誌如:

RewriteRule ^([^/]+)$ index.php?rt=$1 [L,QSA]