3
votes

I have an Azure CDN with a website origin for my domain and it picked www.mydomain.co.uk automatically (with no option for me to change it). I'd rather not use a Storage origin as I have automatic deployment from Github. So, azxxxxxxx.vo.msecnd.net will retrieve content from www.mydomain.co.uk and cache it locally.

However, I have a URL write rule which will redirect www.mydomain.co.uk to mydomain.com (for various SEO reasons). This will cause requests for CDN content to return a 301 redirect, rather than serving up content to the CDN for it to cache. Is there some way to stop the URL rewrite when content is requested by the Azure CDN?

You're more than welcome to see the code and URL rewrite rules at https://github.com/brentnewbury/PersonalSite/blob/master/web.config

1
For the CDN, you use the /cdn path, can you exclude that path from the URL Rewrite rule?Erik Oppedijk
Hi Erik, the code you saw that contains the /cdn is what I eventually came up with. I was going to post it as the answer last night but it was getting a little late.Brent Newbury

1 Answers

2
votes

For others who might want to know how I solved the issue, I decided to write a URL rewrite rule (see below) that looks for /cdn/ and route that through and no longer process other rules. This seems to work nicely. It means references in my HTML will look like //azxxxxxxx.vo.msecnd.net/cdn/img/pic.jpg for a image that is stored in /img/pic.jpg.

<rule name="CDN Passthrough" stopProcessing="true"> 
   <match url="(.*)(cdn/)([\S]+)" /> 
   <action type="Rewrite" url="{R:1}/{R:3}"/> 
</rule>