How to create a 301 redirect in IIS7 using the Rewrite Rule extension for IIS (writes to web.config) that will allow redirecting non-www to www – BUT, I don’t want to use (.*), I want the URL rewriter to ignore URLs like DNS ones, so it can work under Amazon Load Balancer. Without it, Amazon Load Balancer will not be able to read the health check file, because it will be redirected and instead of getting 200OK it will get 301.
So I actually need a rule that will match a URL that contains mydomain.com, or one that start with it of course, so it won’t loop.
The current rule is not good:
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.mydomain\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.mydomain.com/{R:1}" />
</rule>
</rules>
</rewrite>
This will redirect URLs like dns.amzn.com to http://www.mydomain.com – I’ve tried it on IIS7.
Need a better solution
did you come with a solution..
i added a condition using {HTTP_USER_AGENT} to not match ELB (user agent).
This stopped the rule from running for ELB, but i’m just testing this at the moment.
cheers
Added This Also:
The bit you want is