简体   繁体   English

URL重写IIS 7 - 网址重定向无法正常工作

[英]URL Rewrite IIS 7 - url redirect not working

I have a website running on IIS 7 bound to port 80 with 2 domains (for our purposes - example.com & test.com) pointed at it. 我有一个运行在IIS 7上的网站绑定到端口80,有2个域(为了我们的目的 - example.com和test.com)指向它。

example.com is our canonical name so I would like any client that hits test.com to be redirected to example.com. example.com是我们的规范名称,所以我希望任何能够将test.com重定向到example.com的客户端。

I have been trying to use the IIS 7 Rewrite module. 我一直在尝试使用IIS 7 Rewrite模块。 However it doesn't seem to have any effect whatsoever. 然而它似乎没有任何影响。 How can I trouble shoot this? 我怎么能麻烦拍这个呢?

Here's the rule I put in my web.config. 这是我在web.config中添加的规则。

<rewrite>
   <rules>
      <rule name="rule1" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*test.com*" />
          <action type="Redirect" url="{R:1}example.com{R:2}" />
      </rule>
   </rules>
</rewrite>

I was going about it the wrong way. 我是以错误的方式去做的。 This is the way to do it: 这是这样做的方法:

<rule name="Canonical Host Name" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
     <add input="{HTTP_HOST}" negate="true" pattern="^www\.example\.com$" />
  </conditions>
  <action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent" />
</rule>

ref: http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx 参考: http//blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx

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

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