Question

I have written this rule in webconfig to redirect all my resources in thsi folder to my azure blob but it is not showing any image there.

 <rule name="RewriteIncomingCdnRequest" stopProcessing="true">
      <match url="^/CDN/(.*)$" ignoreCase="false"/>
      <action type="Redirect" redirectType="Permanent" url="https://stplatformstorage.blob.core.windows.net/static/{R:0}" />
    </rule>

http://sttest.azurewebsites.net/CDN/image_cdn-trans.png this should redirect to azure storage....

image url on storage https://stplatformstorage.blob.core.windows.net/static/image_cdn-trans.png

Was it helpful?

Solution

you have a bad regular expression - as written, url="^/CDN/(.*)$" would only match /CDN/image_cdn-trans.png - because "^" means "from start of..." -- what you really need is url="^.*/CDN/(.*)$" and then use the matching group {R:1} - for:

<rule name="RewriteIncomingCdnRequest" stopProcessing="true">
  <match url="^.*/CDN/(.*)$" ignoreCase="false"/>
  <action type="Redirect" redirectType="Permanent" url="https://stplatformstorage.blob.core.windows.net/static/{R:1}" />
</rule>

The URL Rewrite module has a great test function to test your regular expressions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top