Rewrite IIS 7 URL - URL redirection not working

I have a website running on IIS 7 connected to port 80 with two domains (for our purposes - example.com and test.com) pointing to it.

example.com is our canonical name, so I would like any client who clicks test.com to be redirected to example.com.

I am trying to use the Rewrite IIS 7 module. However, this does not seem to have any effect. How can i do this?

Here is the rule that I entered in my 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>
+5
source share
1 answer

I did it wrong. 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

+13

All Articles