2014-06-11 28 views
0

我有一些樣本網址我需要改寫:的.htaccess mod_rewrite的,其中包括查詢字符串

RewriteCond %{QUERY_STRING} ^blue-spares-cycle-for-cancer-research$ [NC] 
RewriteRule ^news/news-item/?$ http://www.blue-group.com/en/news/ [R=301,L] 

RewriteCond %{QUERY_STRING} ^blue-spares-appoints-stuart-truckel-as-sales-director$ [NC] 
RewriteRule ^news/news-item/?$ http://www.blue-group.com/en/news/ [R=301,L] 

RewriteCond %{QUERY_STRING} ^project-manager-blue-machinery-london-ltd$ [NC] 
RewriteRule ^about-us/careers/careers-item/$ http://www.blue-group.com/en/about/careers/ [R=301,L] 

RewriteCond %{QUERY_STRING} ^000841:bakers-star-screen$ [NC] 
RewriteRule ^used-machinery/en/screeners/used-machinery-item http://www.blue-group.com/en/used-machinery/ [R=301,L] 

RewriteCond %{QUERY_STRING} ^000751:baler$ [NC] 
RewriteRule ^used-machinery/en/other/used-machinery-item http://www.blue-group.com/en/used-machinery/ [R=301,L] 

RewriteRule ^(.*)$ index.php/$1 [L] 

我的問題是我有很多相似的網址。我是否需要爲每個人創建新的RewriteCond

而且我得到的結果是這樣,例如:

http://www.blue-group.com/en/used-machinery/?000751:baler 
+1

原始如果你問有關合並(不只是'QSA '),然後查看一個'RewriteMap'。 – mario

回答

0

快速谷歌搜索變成了這樣:

保留原始查詢(默認行爲)

RewriteRule ^page\.php$ /target.php [L] 
# from http://example.com/page.php?foo=bar 
# to http://example.com/target.php?foo=bar 

放棄原來的查詢(注意?目標後)

RewriteRule ^page\.php$ /target.php? [L] 
# from http://example.com/page.php?foo=bar 
# to http://example.com/target.php 

替換原來的查詢

RewriteRule ^page\.php$ /target.php?bar=baz [L] 
# from http://example.com/page.php?foo=bar 
# to http://example.com/target.php?bar=baz 

追加新的查詢到原來的查詢(QSA在這裏是關鍵)

RewriteRule ^page\.php$ /target.php?bar=baz [QSA,L] 
# from http://example.com/page.php?foo=bar 
# to http://example.com/target.php?foo=bar&bar=baz 

here