如何使用htaccess将引用链接重定向回索引

时间:2014-06-25 14:40:02

标签: apache .htaccess url mod-rewrite rewrite

我有多个辅助域重定向到我的主域。

实施例。这将被写入www.secondarydomain1.com的htaccess:

RewriteEngine On
RewriteRule ^(.*)$ http://primarydomain.com/?utm_source=redirect&utm_medium=secondarydomain1.com&utm_campaign=301redirect$1 [R=301,L]

我如何编写www.primarydomain.com的htaccess,以便符合以下条件:

如果网址为http://primarydomain.com/?utm_source=redirect&utm_medium=secondarydomain1.com&utm_campaign=301redirecthttp://primarydomain.com/?utm_source=redirect&utm_medium=secondarydomain2.com&utm_campaign=301redirect等, 重定向回到primarydomain.com?

1 个答案:

答案 0 :(得分:1)

将此代码放入DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?primarydomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^utm_source=redirect&utm_medium=((secondarydomain1|secondarydomain2)\.com|secondarydomain3\.me)&utm_campaign=301redirect$ [NC]
RewriteRule ^ /? [L,R=302]