htaccess 根据查询字符串重定向到子域
htaccess redirect to subdomain based on query string
我搜索了类似的问题,但其中 none 个问题适用于我的情况。
我需要做的是从具有特定查询字符串 option=com_virtuemart
的旧 url 重定向到子域:http://parts.domain.com
尝试了一堆规则和条件,但没有实现正确的重定向。它总是将我重定向到 http://parts.domain.com/index.php?option=com_virtuemart
我试过的一些规则:
RewriteCond %{QUERY_STRING} (^|&)option=com_virtuemart(&|$) [NC]
RewriteRule (.*) http://parts.domain.com/ [R=301,L]
RewriteCond %{QUERY_STRING} (^|&)option=com_virtuemart(&|$) [NC]
RewriteRule http://parts.domain.com/? [L,NC,R=301]
喜欢其他 50 条规则。我在这里犯了什么错误?
您只需要结合您的规则。
RewriteCond %{QUERY_STRING} (^|&)option=com_virtuemart(&|$) [NC]
RewriteRule (.*) http://parts.domain.com/? [L,NC,R=301]
在第二个示例中,您没有提供要匹配的正则表达式。
如果您在 parts.domain.com
根目录下,那么您可以在您的 .htaccess 中执行此操作。
这对我有用,您实际上并不需要可以使用的捕获组 ^
。还要确保清除缓存。
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)option=com_virtuemart(&|$) [NC]
RewriteRule ^ http://parts.domain.com/? [L,NC,R=301]
或者你可以这样做。
RewriteEngine On
RewriteCond %{THE_REQUEST} [A-Z]{3,}\ /+(index\.php)?\?option=com_virtuemart [NC]
RewriteRule ^ http://parts.domain.com/? [R=301,L]
我搜索了类似的问题,但其中 none 个问题适用于我的情况。
我需要做的是从具有特定查询字符串 option=com_virtuemart
的旧 url 重定向到子域:http://parts.domain.com
尝试了一堆规则和条件,但没有实现正确的重定向。它总是将我重定向到 http://parts.domain.com/index.php?option=com_virtuemart
我试过的一些规则:
RewriteCond %{QUERY_STRING} (^|&)option=com_virtuemart(&|$) [NC]
RewriteRule (.*) http://parts.domain.com/ [R=301,L]
RewriteCond %{QUERY_STRING} (^|&)option=com_virtuemart(&|$) [NC]
RewriteRule http://parts.domain.com/? [L,NC,R=301]
喜欢其他 50 条规则。我在这里犯了什么错误?
您只需要结合您的规则。
RewriteCond %{QUERY_STRING} (^|&)option=com_virtuemart(&|$) [NC]
RewriteRule (.*) http://parts.domain.com/? [L,NC,R=301]
在第二个示例中,您没有提供要匹配的正则表达式。
如果您在 parts.domain.com
根目录下,那么您可以在您的 .htaccess 中执行此操作。
这对我有用,您实际上并不需要可以使用的捕获组 ^
。还要确保清除缓存。
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)option=com_virtuemart(&|$) [NC]
RewriteRule ^ http://parts.domain.com/? [L,NC,R=301]
或者你可以这样做。
RewriteEngine On
RewriteCond %{THE_REQUEST} [A-Z]{3,}\ /+(index\.php)?\?option=com_virtuemart [NC]
RewriteRule ^ http://parts.domain.com/? [R=301,L]