Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS 7 URL Rewrite rules aren't being applied

I have a .net 4.0 web application hosted on IIS7 server.

After reading this: http://learn.iis.net/page.aspx/496/iis-url-rewriting-and-aspnet-routing/ about serving static content from another server, so that cookies aren't sent with every request for a static file, i tried it out but without much success.

This is the part written in the web.config file:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="images" stopProcessing="true">
                <match url="^images/(.*)$" />
                <action type="Rewrite" url="http://static-server.com/images/{R:1}" appendQueryString="true" logRewrittenUrl="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

With this rule defined, every link to a file in the images folder should be rewriten into the static-server URL. But this doesn't work at all, now every image that is in the images folder returns a 404 not found. Any idea on what could be causing this behavior or a different solution on how to serve files from a specific folder from a different server without having to go trough tons of code and change all the links to link to the static server?

I did also try using the Redirect action type instead of the Rewrite action, which actually worked, but it defies the reason why i'm trying to serve the files on a different server (this way the request is sent to my dynamic content server with all the required cookies and is redirected to the static-server which is actually worse than serving the images from the dynamic content server).

like image 296
Atzoya Avatar asked Nov 09 '10 13:11

Atzoya


1 Answers

I don't think that rule alone will solve this problem for you. It probably doesn't rewrite links in pages that are sent to users.

The article you linked to suggests that you do this "together with the IIS Application Request Routing module". It's the routing module that actually changes links within files sent to the client.

like image 194
Michael Haren Avatar answered Oct 14 '22 06:10

Michael Haren