繁体   English   中英

IIS重写规则将特定域URL重定向到同一域上的不同URL

[英]IIS rewrite rule to redirect specific domain url to different url on same domain

我只想要一个IIS 7.5重写规则将http://www.domain.com/url1重定向到http://www.domain.com/url2 (同一个域)。 这可以通过以下方式实现:

<rule name="Redirect url" enabled="true" stopProcessing="true">
    <match url="^url1" />
    <action type="Redirect" url="http://www.domain.com/url2"
      appendQueryString="false" redirectType="Permanent" />
</rule>

但是,该网站会监听多个域名,因此上述内容成为所有域名的全局规则。 如何将此特定于domain.com? 尝试更改匹配URL并添加条件但无法使其工作。 谢谢。

我让它以这种方式工作:

<rule name="Redirect url1" stopProcessing="true">
     <match url="^url1$" />
     <conditions>
          <add input="{HTTP_HOST}" pattern="^(www.)?domain.com$" />
     </conditions>
     <action type="Redirect" url="http://www.domain.com/url2"
      appendQueryString="false" redirectType="Permanent" />
</rule>

使用此页面上的答案,我能够为自己调整规则。 我还添加了查询参数。 想在这里发布,万一它可以帮助某人:

<!-- probably requires custom rewrite module, available through web platform installer -->
<rule name="Redirect oldsite.com" stopProcessing="true">
    <match url=".*" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^.*oldsite\.com$" />
    </conditions>
    <action type="Redirect" url="http://www.newsite.com/page.cfm?userid=123&amp;mode=form"
      appendQueryString="false" redirectType="Permanent" />
</rule>

一些解释:

为了消除一些混淆,这个“url”是域之后的第一个斜线之后的部分,而不是整个url。 我将把它放入这个以便它获取任何URL。

<match url=".*" />

现在,我们将添加一个条件,因为我在这台计算机上有多个网站,因此我想确保此规则仅适用于其中一个。 我还使用了通配符而不是“(www。)?” 因为通配符将捕获任何子域。

<conditions>
    <add input="{HTTP_HOST}" pattern="^.*oldsite\.com$" />
</conditions>

最后一个注释适用于想要放入多个查询字符串参数的人。你需要在它们之间转义&符号,因为如果不这样做,它将无效:

<action type="Redirect" url="http://www.newsite.com/page.cfm?userid=123&amp;mode=form"
  appendQueryString="false" redirectType="Permanent" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM