htaccess 重定向同时解析查询字符串和变量
htaccess redirect whilst parsing query string and variable
如何在捕获“?”之后的任何内容的同时重定向子域?并使用 htaccess 附加到重定向,同时维护特定变量?
重定向自...
http://subdomain1.example.com/?retailcentre=subdomain1&utm_source=twitter&utm_medium=twitter&utm_campaign=022641example
到...
http://www.example.com/?retailcentre=subdomain1&utm_source=twitter&utm_medium=twitter&utm_campaign=022641example
'?' 之后的查询字符串可以是来自 twitter、facebook 等的任何内容
必须解析的一个变量是重定向来自哪个子域,在本例中为 'retailcentre'。
试试:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain1\.example\.com$ [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI}?retailcentre=subdomain1 [QSA,NE,R=301,L]
[QSA]
Flag:当替换URI包含查询字符串时,RewriteRule的默认行为是丢弃现有的查询字符串,并用新生成的查询字符串替换它。使用 [QSA] 标志会合并查询字符串。
您可以使用以下规则:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{THE_REQUEST} /\?retailcentre=.+&utm_source=.+&utm_medium=.+&utm_campaign=.+\sHTTP [NC]
RewriteRule ^ http://example.com/ [L,R,NE]
如何在捕获“?”之后的任何内容的同时重定向子域?并使用 htaccess 附加到重定向,同时维护特定变量?
重定向自...
http://subdomain1.example.com/?retailcentre=subdomain1&utm_source=twitter&utm_medium=twitter&utm_campaign=022641example
到...
http://www.example.com/?retailcentre=subdomain1&utm_source=twitter&utm_medium=twitter&utm_campaign=022641example
'?' 之后的查询字符串可以是来自 twitter、facebook 等的任何内容
必须解析的一个变量是重定向来自哪个子域,在本例中为 'retailcentre'。
试试:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain1\.example\.com$ [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI}?retailcentre=subdomain1 [QSA,NE,R=301,L]
[QSA]
Flag:当替换URI包含查询字符串时,RewriteRule的默认行为是丢弃现有的查询字符串,并用新生成的查询字符串替换它。使用 [QSA] 标志会合并查询字符串。
您可以使用以下规则:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{THE_REQUEST} /\?retailcentre=.+&utm_source=.+&utm_medium=.+&utm_campaign=.+\sHTTP [NC]
RewriteRule ^ http://example.com/ [L,R,NE]