I often create a canonical host name URL Rewrite rule for a production site so that requests redirect to a single domain -- for example from alexlindgren.com to www.alexlindgren.com. For sites hosted with Azure App Service using deployment slots, we only want the production slot to redirect, otherwise going to the staging slot will redirect you to production since each slot uses uses the same web.config. To handle this, one can just add the non production domains to the conditions as seen in this gist.
Created
December 2, 2016 17:20
-
-
Save alindgren/999c542a6625ddfb41f1b0293878dcad to your computer and use it in GitHub Desktop.
Canonical Domain Redirect for Azure App Service deployment slots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<configuration> | |
<system.webServer> | |
<rewrite> | |
<rules> | |
<rule name="CanonicalHostNameRule"> | |
<match url="(.*)"/> | |
<conditions> | |
<add input="{HTTP_HOST}" pattern="^localhost$" negate="true"/> | |
<add input="{HTTP_HOST}" pattern="^sitename-staging\.azurewebsites\.net$" negate="true"/> | |
<add input="{HTTP_HOST}" pattern="^www\.sitename\.com$" negate="true"/> | |
</conditions> | |
<action type="Redirect" url="http://www.sitename.com/{R:1}"/> | |
</rule> | |
</rules> | |
</rewrite> | |
</system.webServer> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment