Not rewrite images and css

Aug 3, 2011 at 9:01 AM


I´m using the follow rules:

RewriteLog  c:\temp\iirfLog.out
RewriteLogLevel 3

RewriteRule ^/ofertas/folletos/(.*)/(.*)/(App_Themes|Images)/(.*)$ - [L,I]
RewriteRule ^/ofertas/folletos/(.*)/([^/]+)  /ProductList.aspx?seg=$2 [L]


The problems is with the images and css relative paths

Any solutions?

Aug 3, 2011 at 1:45 PM

Let's see.... "The problem is with the images and css relative paths"

You didn't say, but the usual problem in this case is that the page url gets rewritten, and references to css, images and script (.js) from within the page, are not relatively specified. In other words, the page includes a reference to a css, and that reference does not depend on the page URL.  When the page gets rewritten, the CSS url does not change.  Therefore, the resulting request for the CSS will not be /ofertas/folletos/something/Something/App_Themes/style.css.  Instead the request for the CSS may arrive at the server as  /App_Themes/style.css , when the page URL being used by the browser is /ofertas/folletos/something/Something.    I am guessing here, at the exact URLs, but the main point is that your CSS and Image URLs do not match what you expect, because they are absolutely qualified in the aspx page output.

If that's the case, then, your first rule, in which you are attempting to exclude CSS and Images from the rewriting, does not match the incoming CSS and image urls, because they are absolute.

The other alternative is that your CSS and Image URLs are relative in the page content, and they arrive and DO MATCH the first rule. They are then submitted to the IIS server unchanged, and IIS delivers a 404 because there is no document at /ofertas/folletos/something/Something/App_Themes/style.css .

In either case, what you need to do is verify the URLs being sent for css and images.  A good way to do that is using an http debugging proxy, a tool like Fiddler. It will show you all HTTP requests being sent by the browser, and you will see precisely which URLs the browser is requesting for CSS and Images. Then, you can modify your ini file to match those URLs and do whatever is necessary - probably an actual rewrite instead of using the "don't rewrite" rule.

good luck.