IIS7 URL rewrite map to other external domain

Rovi31 used Ask the Experts™
I have a website in which the map "/img" must be redirected to another domain. The other domain can be an external one.

so "http://www.mydomain.com/img/test/demo.jpg" must be redirected to "http://www.otherdomain.com/img/test/demo.jpg"

i also have a <base href="http://www.mydomain.com/">, so the URL to be redirected will be most of the time "img/test/demo.jpg ", which then also should be redirected to to "http://www.otherdomain.com/img/test/demo.jpg"

i currently have this, but it doesn't work

     <rule name="Change image linking" stopProcessing="false">  
        <match url=".*\.(gif|jpg|png)$" />  
             <add input="{HTTP_HOST}" pattern="img/(.*)$" />  
      <action type="Redirect" url="http://www.otherdomain.com/{C:1}" appendQueryString="false" redirectType="Permanent" />  

Open in new window

How can i do that (in the web.config)

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004
Your rule is comparing the hostname, which is probably not going to match "img/".  You need to compare the name of the request, instead.  Something like this may work:

<match url="/?(img/.*(gif|jpg|png))$" />
<action type="Redirect" url="http://www.otherdomain.com/{R:0}" appendQueryString="false" redirectType="Permanent" />

Open in new window

You may need to fiddle with the {R:0} parameter to get the proper return.  This rule assume it is running from the document root, and the images being redirected are all in /img.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial