Htaccess - 301重定向与分析广告系列参数

时间:2015-08-03 21:50:57

标签: .htaccess mod-rewrite redirect google-analytics http-status-code-301

我将多个域定向到带有.htaccess的文件夹 我的htaccess看起来像这样:

RewriteEngine On

rewritecond %{http_host} ^domain-2.com
rewriteRule ^(.*) https://domain-1.com/?utm_source=redirects&utm_medium=domain-2.com&utm_campaign=301 [R=301,L]

rewritecond %{http_host} ^domain-3.com
rewriteRule ^(.*) https://domain-1.com/?utm_source=redirects&utm_medium=domain-3.com&utm_campaign=301 [R=301,L]

我希望更有效,更优雅 - 所有域名都会重定向到 domain-1.com

是否存在如何在URL参数中使用{HTTP_HOST}或类似内容的方式?

1 个答案:

答案 0 :(得分:1)

尝试:

RewriteEngine On
RewriteCond %{HTTP_HOST} !domain-1\.com$ [NC]
RewriteRule ^(.*)$ https://domain-1.com/?utm_source=redirects&utm_medium=%{HTTP_HOST}&utm_campaign=301 [R=301,L]