IIS7 URL将多个域重写到单个域,包括谷歌分析引用代码 [英] IIS7 URL Rewrite multiple domains to a single domain including google analytics referral code
问题描述
我试图优雅地捕捉大量需要重定向到单个域名的域名: b b mydomain.com ,www.mydomain.com,mydomain-eu.com,mydomain.eu
全部到主域名:
<我可以很容易地在IIS中创建一个网站 - 绑定所有的域名和密码做一个重定向。
但是有一个问题。客户想要追踪那些重定向来自谷歌分析的地方。
因此,他们需要一些参数在重定向URL中传递,例如(使用上面的域):
mydomain.eu
重定向到:
www.mydomain.co.uk?utm_campaign=mydomain.eu&utm_source = mydomain.eu& utm_medium = referral
所以 - 这是使用URL重写的好例子。这是我在web.config中的内容:
< rule name =Redirectenabled =falsepatternSyntax = 通配符stopProcessing =true>
< match url =(。*)/>
<条件>
< add input ={HTTP_HOST}pattern =^ www.mydomain.co.uk $negate =true/>
< / conditions>
< / rule>
如果输入与我想要的域名不匹配,我正在重定向它。
除了一件事情之外,它完美地工作。我只是不能得到原始域的参数。 {R:0}返回空白。我也试过{C:0}。我已经在GUI中测试了模式,他们告诉我我应该得到所需的域名。
我做错了什么?感谢。
这是一个猜测,但如何:
< rule name =Redirectenabled =falsepatternSyntax =WildcardstopProcessing =true>
< match url =(。*)/>
<条件>
< add input ={HTTP_HOST}pattern =^ www.mydomain.co.uk $negate =true/>
< / conditions>
< action type =Redirecturl =http://www.mydomain.co.uk/?utm_campaign={HTTP_HOST}&utm_source={HTTP_HOST}&utm_medium=referral />
< / rule>
仔细一看,它表示您可以在此文档中以这种方式使用它:
I am trying to elegantly capture a large number of domains that need to redirect to a single domain for example:
mydomain.com, www.mydomain.com, mydomain-eu.com, mydomain.eu
all to the main domain:
www.mydomain.co.uk
This I can do fairly easily in IIS by creating a site - binding all the domains and doing a redirect.
However there is a catch. The client wants to track where those redirects came from in google analytics.
So they need some parameters passing in the redirect URL, example (using a domain from above):
mydomain.eu redirects to: www.mydomain.co.uk?utm_campaign=mydomain.eu&utm_source=mydomain.eu&utm_medium=referral
So - this is a good case to use a URL rewrite. This is what I have in the web.config:
<rule name="Redirect" enabled="false" patternSyntax="Wildcard" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.mydomain.co.uk$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.mydomain.co.uk/?utm_campaign={R:0}&utm_source={R:0}&utm_medium=referral" />
</rule>
If the input does not match the domain I want to be I am redirecting it.
It works perfectly apart from one thing. I just cant get the parameter of the original domain. The {R:0} returns blank. I have tried {C:0} also. I have tested the patterns in the GUI and they tell me I should be getting the requested domain.
What am I doing wrong? Thanks.
This is a guess but what about:
<rule name="Redirect" enabled="false" patternSyntax="Wildcard" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.mydomain.co.uk$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.mydomain.co.uk/?utm_campaign={HTTP_HOST}&utm_source={HTTP_HOST}&utm_medium=referral" />
</rule>
Looked this up and it says you can use it this way in this documentation:
这篇关于IIS7 URL将多个域重写到单个域,包括谷歌分析引用代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!