2014-09-24 127 views
1

請幫助解決這些重定向:的.htaccess重定向頁面變量

重定向1.類/選項=值=> domain.com/category/page.html

RewriteCond %{QUERY_STRING} ^option=value(&.*)?$ [NC] 
RewriteRule ^category/$ http://domain.com/category/page.html%1 [R=301,NE,NC,L] 

重定向2.類別/子%26-類別/?選項=值=> domain.com/category/page1.html

RewriteCond %{QUERY_STRING} ^option=value(&.*)?$ [NC] 
RewriteRule ^category/sub-\x26-category/$ http://domain.com/category/page1.html%1 [R=301,NE,NC,L] 

回答

1

您需要使用?在目標URI去掉所有現有的查詢字符串:

RewriteCond %{QUERY_STRING} ^option=value(&.*)?$ [NC] 
RewriteRule ^category/$ /category/page.html? [R=301,NE,NC,L] 

RewriteCond %{QUERY_STRING} ^option=value(&.*)?$ [NC] 
RewriteRule ^category/sub-\x26-category/$ /category/page1.html? [R=301,NE,NC,L] 

確保這些規則被放置在其他內部路由規則。

+0

>確保將這些規則放置在其他內部路由規則之上。 – 2014-09-24 20:29:51

+0

非常感謝,我添加了重定向到.htaccess的開始,他們現在工作 – 2014-09-24 20:30:40

+0

不客氣,很高興它解決了。 – anubhava 2014-09-24 20:32:29