For SEO optimization reason, I get all requests to http://Example.com
redirected to http://www.Example.com
. The problem is that when working on local, requests to localhost
get redirected as well.
I tried the suggestion in this Rewrite rule to HTTPS except when on localhost answer with no luck.
Here is my actual redirection rule located in Web.Config
(hopefully it can help someone that is looking for Rewrite rule to WWW):
<system.webServer>
<rewrite>
<rules>
<rule name="redirect example.com to www.example.com">
<match url="^(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
Any help?