EDIT:
To be able to rewrite (and not just redirect) URLs to external websites, you need to install the application request routing module and enable proxy mode.
For this:
- Download and install the module
- Open the IIS Management Console (
inetmgr ) - Choose node server
- Double click on
Application Request Routing Cache : 
- Click
Server Proxy Settings in the Actions panel (to the right of the screen) - Check
Enable proxy and click Apply 
The second step is to configure your rules.
If you want your rewrite to be path based, use the following code:
<rewrite> <rules> <rule name="Rewrite to cdn domain"> <match url="^images/folder/(.+)$" /> <action type="Rewrite" url="http://cdn.domain.com/images/folder/{R:1}" /> </rule> </rules> </rewrite>
Or, if you keep the same folder architecture on a second website, you can simplify the following:
<rewrite> <rules> <rule name="Rewrite to cdn domain"> <match url="^images/folder/(.+)$" /> <action type="Rewrite" url="http://cdn.domain.com/{R:0}" /> </rule> </rules> </rewrite>
If you want to catch only files ending in a specific extension (say, images):
<rewrite> <rules> <rule name="Forward to cdn domain"> <match url="^images/folder/.+\.(?:jpg|bmp|gif)$" /> <action type="Rewrite" url="http://cdn.domain.com/{R:0}" /> </rule> </rules> </rewrite>
Refer to: http://www.iis.net/learn/extensions/url-rewrite-module/iis-url-rewriting-and-aspnet-routing (section " Which option to use? ")
Tip:
The best way to test your pattern is to use the IIS test pattern tool.
At the root of your site -> URL Rewrite -> Create an empty rule -> click a test pattern: 
If you donโt get the expected result, you can debug your correspondence using the Failover Query Tracking Tool
cheesemacfly
source share