0

Here is a problem I have been struggling with for a while.
I host a website with the address www.mywebsite.com in server I but the images of the site come from server II (ip: 1.2.3.4) so if there are requests such as www.mywebsite.com/images/123.jpg I would like to redirect them to the image server(Server II).

I would like that requests that contain (.*jpg.*) regex will redirect to Server II.

  1. Using Url rewrite I added a rule:

    <rewrite>
            <rules>
                <rule name="Ignore images requests" enabled="true" stopProcessing="true">
                    <match url="(.*jpg.*)" />
                    <action type="Rewrite" url="https://www.petfinder.com/wp-content/uploads/2012/11/91615172-find-a-lump-on-cats-skin-632x475.jpg" />
                </rule>
            </rules>
        </rewrite> 
    

It rewrites the request to a static image as you can see, how can I define it to go to 1.2.3.4/images/imagename.jpg?

The best solution would be if I could just ignore requests containing jpg via my host file, is there a way to that?

Offir
  • 3,252
  • 3
  • 41
  • 73
  • Can you please provide samples of your source and destination url for images? It will help me to create proper rule for you – Victor Leontyev Jul 05 '17 at 19:42
  • @VictorLeontyev I would like that when the url contains jpg the it will redirect the request to the original server. For example if I have: `https://styleplace/UserFiles/Entities/TopBanners/top50161616_586.jpg` – Offir Jul 06 '17 at 08:28
  • And image is accessible in original server by this url? : `https://1.2.3.4/UserFiles/Entities/TopBanners/top50161616‌​_586.jpg` – Victor Leontyev Jul 06 '17 at 08:30
  • @VictorLeontyev yes – Offir Jul 06 '17 at 10:14

1 Answers1

1

You redirect rule should be like that:

<rule name="image redirect" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" pattern="(.*?)\.jpg$" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" />
    </conditions>
  <action type="Redirect" url="http://1.2.3.4/{R:1}" appendQueryString="false" />                           
</rule>

It will redirect all requests to files with .jpg extension to 1.2.3.4 domain For example:

http://www.mywebsite.com/dog-1210559_960_720.jpg to http://1.2.3.4/dog-1210559_960_720.jpg

http://www.mywebsite.com/UserFiles/Entities/TopBanners/top50161616‌​_586.jpg to http://1.2.3.4/UserFiles/Entities/TopBanners/top50161616‌​_586.jpg

Victor Leontyev
  • 8,488
  • 2
  • 16
  • 36
  • So far it didn't work because I found out I don't have access to the remote server, I try to solve this issue and try again your code. – Offir Jul 06 '17 at 13:14