Created
October 24, 2014 22:17
-
-
Save brentnewbury/d9cecf99e3550c464ae9 to your computer and use it in GitHub Desktop.
URL rewrite rule for Azure CDN with Azure Websites origin which avoids interference from other URL rewrite rules when Azure CDN picks the wrong domain
This file contains 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
<html> | |
<head> | |
<title>Example.com</title> | |
</head> | |
<body> | |
<img src="//azxxxxxx.vo.msecnd.net/cdn/img/example.png" /> <!-- CDN will receive a HTTP 200 with the image content, thanks to the "CDN Passthrough" rewrite rule --> | |
<img src="//azxxxxxx.vo.msecnd.net/img/example.png" /> <!-- Normal Azure CDN URI which will recieve a 301 redirect if Azure CDN chooses www.example.com as the origin domain--> | |
<img src="/img/example.png" /> <!-- Non CDN edge cached content --> | |
</body> | |
</html> |
This file contains 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="CDN Passthrough" stopProcessing="true"> | |
<match url="(.*)(cdn/)([\S]+)" /> | |
<action type="Rewrite" url="{R:1}/{R:3}"/> | |
</rule> | |
<rule name="Remove WWW - Causes 301 redirect affecting the Azure CDN requests if it choses www.example.com as the origin domain" stopProcessing="true"> | |
<match url="(.*)" /> | |
<conditions> | |
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" /> | |
</conditions> | |
<action type="Redirect" url="http://{C:2}{PATH_INFO}" redirectType="Permanent" /> | |
</rule> | |
</rules> | |
</rewrite> | |
</system.webServer> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment