Reputation: 239
I have 2 custom domains set up on Azure Websites: mydomain.lt and www.mydomain.lt
DNS registrar's settings:
Subdomain and redirect:
awverif -> CNAME: awverify.mydomain.azurewebsites.net
www -> CNAME: mydomain.azurewebsites.net
Other redirects: IP: 137.x.x.x (IP address provided by Azure) and MX: 79.x.x.x
I can reach my website via mydomain.lt and www.mydomain.lt
What I am trying to do now is to set my Canonical URL in a way, that users coming from www.mydomain.lt would be automatically redirected to mydomain.lt and all relative URL paths returned in a lower case.
I added settings bellow to system.WebServer on Web.config:
<rewrite>
<rules>
<!-- SEO | Section 1 | Whitelist -->
<rule name="Whitelist - Resources" stopProcessing="true">
<match url="^(?:css/|scripts/|bundles/|images/|install/|config/|umbraco/|umbraco_client/|base/|webresource\.axd|scriptresource\.axd|__browserLink|[^/]*/arterySignalR/.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="None" />
</rule>
<!-- SEO | Section 2 | Rewrites (chaining) -->
<rule name="SEO - Lower case" stopProcessing="false">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_METHOD}" pattern="GET" />
<add input="{R:1}" pattern="[A-Z]" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="_{ToLower:{R:1}}" />
</rule>
<!-- SEO | Section 3 | Redirecting -->
<rule name="SEO - HTTP canonical redirect" stopProcessing="true">
<match url="^(_*)(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="^www\.(.*)" />
<add input="{HTTP_METHOD}" pattern="GET" />
<add input="{SERVER_PORT}" pattern="80" />
</conditions>
<action type="Redirect" url="http://{C:1}/{R:2}" />
</rule>
<rule name="SEO - Non-canonical redirect" stopProcessing="true">
<match url="^(_+)(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_METHOD}" pattern="GET" />
</conditions>
<action type="Redirect" url="{R:2}" />
</rule>
</rules>
</rewrite>
The resulting behaviour is a redirect loop. Any ideas how to fix this problem?
Upvotes: 1
Views: 1729
Reputation: 239
It seems the problem is with Azure Websites. The link below gives a workaround how to fix the problem temporarily.
I've rewritten my rules and everything works just fine:
<rewrite>
<rules>
<rule name="Whitelist - Resources" stopProcessing="true">
<match url="^(?:css/|scripts/|bundles/|content/|images/|install/|config/|umbraco/|umbraco_client/|base/|webresource\.axd|scriptresource\.axd|__browserLink|[^/]*/arterySignalR/.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="None" />
</rule>
<rule name="Convert to lower case" stopProcessing="true">
<match url=".*[A-Z].*" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
</rule>
<rule name="Canonical Host Name" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll">
<add input="{REMOTE_PORT}" pattern="*" />
<add input="{HTTP_HOST}" pattern="mydomain.lt" negate="true" />
</conditions>
<action type="Redirect" url="http://mydomain.lt/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
Upvotes: 1
Reputation: 12174
Start by simplifying your rewrite rules to narrow down the problem:
<!-- SEO | Section 2 | Rewrites (chaining) --> <rule name="SEO - Lower case" stopProcessing="false"> <match url="(.*)" ignoreCase="false" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> <add input="{HTTP_METHOD}" pattern="GET" /> <add input="{R:1}" pattern="[A-Z]" ignoreCase="false" /> </conditions> <action type="Redirect" url="{ToLower:{R:1}}" RedirectType="Permanent"/> </rule>
Upvotes: 0