htaccess根据查询字符串重定向到子域
I searched for similar questions but none of them was applicable to my situation.
What I need to do is redirect from old url's that have specific query string: option=com_virtuemart
to a subdomain : http://parts.domain.com
Tried bunch of rules and conds but haven't achieved right redirection. It was always redirecting me to http://parts.domain.com/index.php?option=com_virtuemart
Some of the rules I tried:
RewriteCond %{QUERY_STRING} (^|&)option=com_virtuemart(&|$) [NC]
RewriteRule (.*) http://parts.domain.com/$1 [R=301,L]
RewriteCond %{QUERY_STRING} (^|&)option=com_virtuemart(&|$) [NC]
RewriteRule http://parts.domain.com/? [L,NC,R=301]
And like 50 other rules. What mistakes I'm doing here?
我搜索了类似的问题,但没有一个适用于我的情况。 p>
我需要做的是从具有特定查询字符串的旧URL重定向: 尝试了一堆规则和条件,但没有实现正确的重定向。 它总是将我重定向到 我试过的一些规则: p>
和其他50条规则一样。 我在这里犯了什么错误? p>
div> option = com_virtuemart code>到子域:
http://parts.domain.com code> p>
http://parts.domain.com/index.php?option=com_virtuemart code> p>
RewriteCond%{QUERY_STRING}(^ |&)option = com_virtuemart(& | $)[NC]
RewriteRule(。*)http://parts.domain.com / $ 1 [R = 301,L]
RewriteCond%{QUERY_STRING}(^ |&)option = com_virtuemart(& | $)[NC]
RewriteRule http://parts.domain.com/? [L,NC,R = 301]
code> pre>
You just needed to combine your rules.
RewriteCond %{QUERY_STRING} (^|&)option=com_virtuemart(&|$) [NC]
RewriteRule (.*) http://parts.domain.com/? [L,NC,R=301]
In the second example, you had not provided the regular expression to match.
If you are on the parts.domain.com
root, then you can do this in your .htaccess.
This works for me you don't really need a capture group you can use ^
. Also make sure you clear your cache.
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)option=com_virtuemart(&|$) [NC]
RewriteRule ^ http://parts.domain.com/? [L,NC,R=301]
Or you could do something like this.
RewriteEngine On
RewriteCond %{THE_REQUEST} [A-Z]{3,}\ /+(index\.php)?\?option=com_virtuemart [NC]
RewriteRule ^ http://parts.domain.com/? [R=301,L]