Mobile app version of vmapp.org
Login or Join
Holmes151

: URL Rewrite in IIS 7.5 I have a web site (hosted on IIS 7.5) that has bindings to four URLs. Something like: www.example.com example.com www.example.net example.net What I would like to accomplish

@Holmes151

Posted in: #Seo #UrlRewriting

I have a web site (hosted on IIS 7.5) that has bindings to four URLs. Something like:

example.com example.com example.net example.net


What I would like to accomplish using URL Rewrite is that:


Surfing to example.com will auto redirect to example.com (and return 301)
Surfing to example.net will auto redirect to example.net (and return 301)


I tried using the URL Rewrite (I have no experience using this feature) using the IIS MANAGER > FEATURES > URL Rewrite > Add Rule > canonical domain name, but the problem is that then I can choose one address of those four, that will cause all the other three to be redirected to that, which is not what I need to do.

Can you please help and advise? Is URL Rewrite is a good and possible way to do this?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Holmes151

1 Comments

Sorted by latest first Latest Oldest Best

 

@Gonzalez347

Here is the solution:

Add the following rules to the web config:

<system.webServer>
<rewrite>
<rules>
<rule name="Redirect domain 1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.example.com$" />
</conditions>
<action type="Rewrite" url="http://example.com/{R:1}" />
</rule>
<rule name="Redirect domain 2">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.net$" />
</conditions>
<action type="Redirect" url="http://www.example.net/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme