如果找到某个查询模式,则htaccess重定向

时间:2014-02-10 11:52:53

标签: apache .htaccess url-rewriting

我想从

重定向
www.site1.info?index.php?id=243&L=&tx_kesearch_pi1%5Bsword%5D=YOU
www.site1.info/search/search/?L=&tx_kesearch_pi1[sword]=YOU

www.site2.org?index.php?id=243&L=&tx_kesearch_pi1%5Bsword%5D=YOU
www.site2.org/search/search/?L=&tx_kesearch_pi1[sword]=YOU

注意

我只想重新定位,如果......

www.site1.info?index.php?id=243
www.site1.info/search/search/

...而不是重定向正在进行的查询(将其移植到site2.org

我尝试失败了:

RewriteCond %{HTTP_HOST} ^(www\.)site1\.info/index.php?id=243$ [NC]
RewriteRule ^ http://www.site2.org/index.php?id=243%{REQUEST_URI} [NE,R=301,L]

1 个答案:

答案 0 :(得分:1)

您无法与REQUEST_URI中的QUERY_STRINGRewriteCond %{HTTP_HOST}匹配。

您可以使用此代码:

RewriteCond %{HTTP_HOST} ^(www\.)site1\.info$ [NC]
RewriteCond %{QUERY_STRING} (?:^|&)id=243(?:&|$) [NC]
RewriteRule ^index\.php$ http://www.site2.org/index.php?id=243%{REQUEST_URI} [NE,R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)site1\.info$ [NC]
RewriteRule ^search/search/?$ http://www.site2.org/index.php?id=243%{REQUEST_URI} [NE,R=301,L]