Newby Triyng to start with url rewrite

Topics: Developer Forum, User Forum
Apr 22, 2011 at 5:48 AM
Edited Apr 22, 2011 at 5:49 AM

Hello, im newby on this so i will tell you what i want to do : 

I successfully tried to use url rewirte to rewrite some urls.

The problem is that i have css and scripts folders and i cant read those files from the rewrited file since i added directory/file to read theme.

if i call css file from the original location its ok. But if i add a directory i the file cant be located.

Thanks for your help.


Gustavo W. - Hosting Services

Apr 25, 2011 at 8:55 PM

Yes, this is a common problem.

To work around it, the simplest thing is to introduce a rule for the .js and .css to "un-rewrite them".  When a rewritten page is delivered to the browser, the browser then requests the download of the css and js that are referenced within. At this point, one of two things happens:  (a) those new requests are rewritten by IIRF, to a location where they cannot be found, or (b) those requests are NOT rewritten, and they should be. 

The solution is pretty simple to describe, but may be less simple to implement: modify your rewrite rules to rewrite requests for css and scripts appropriately.

To help figure out just what requests are arriving for CSS and .JS, I suggest that you use a debugging HTTP proxy like Fiddler2.  It's easy and will give you new insights.

Download fiddler (Free) and install it.  Turn it on.  Then using the browser, request a page that gets rewritten by IIRF.  Then examine the fiddler log to see requests for .js and .css URLs.  You will then be able to figure out which rules you need to change, or which rules you need to introduce, to properly handle these requests.  Your goal is to convince IIS to respond constructively to the request for the .js and .css (and .gif etc) files.

The reason I cannot give you a simple "one size fits all" answer is that

  • I don't know your rules
  • I don't know whether your css and js files (etc) use relative references or not.  Or maybe there is a mix.



Apr 26, 2011 at 2:17 AM
Edited Apr 26, 2011 at 2:18 AM

Thanks for your response. I will try with HTTP proxy like Fiddler2.

I know the problem. I added rules for css and js files, also images. The problem is that my rule for images doesnt cover subfolders on it.

Example : 

My rule is : RewriteRule ^/argentina/Images/([^/]*)$     /Images/$1 [L]

But i cant locate files on Images/prettyPhoto/light_square/somefiles.jpg

Again thanks for your help.


Gustavo W. - Hosting Services

Apr 26, 2011 at 6:08 PM

Hello Gustavo.

What does it mean when you write:

But i cant locate files on Images/prettyPhoto/light_square/somefiles.jpg


Apr 26, 2011 at 7:44 PM

Hello Cheeso,

I mean that i made my rule on folder "Images", but the rule does not apply for subfolders on that folder (Images/SomFolder).

For example : if i have images on Images/somefolder/image.jpg my rule is not able to read this file since is on a subfolder in Images folder.

if i call to an image on "images" folder there is no problem with it, the rule is working fine.

Thanks again


Apr 26, 2011 at 9:16 PM
Edited Apr 26, 2011 at 9:18 PM

Let me take one step back.

you have a rule like this:

RewriteRule ^/argentina/Images/([^/]*)$     /Images/$1 [L]

What that says to IIRF is, when a request for /argentina/Images/Foo.jog comes in, then rewrite it to /Images/Foo.jpg.

This rule matches any URL where there is no additional slash following /argentina/Images/ . Notice the ([^/]*) . This can be stated in English as "zero or more characters, none of which are slash." In practice, if you have an incoming request like /argentina/Images/small/Bar.jpg, your rule will not match, because the thing that follows /argentina/Images/ - in this example "small/Bar.jpg" - includes a slash.

Are you saying that you want your rule to match such urls? If so, then try something like this:

RewriteRule ^/argentina/Images/(.+\.(jpg|gif|png|bmp))$     /Images/$1 [L]

That says, "a series of one or more characters, followed by a dot, and one of the following: {jpg, bmp, gif, or png}."  A request like /argentina/Images/small/Bar.jpg will be rewritten to /Images/small/Bar.jpg

Apr 26, 2011 at 10:07 PM

I understand the rule and now im using it, but it still not working with subfolders ):

Maybee because those images called from a css file? i made a rule for css also and its working fine.

Also tried to make a rule to the subfolder directly : 

RewriteRule ^/argentina/Images/prettyPhoto/light_rounded/(.+\.(jpg|gif|png|bmp))$            /Images/prettyPhoto/light_rounded/$1 [L]

but im not able to get those images ):

I hope you can help me, else, thank you very much for your precious time (:

Apr 26, 2011 at 10:41 PM
Edited Apr 28, 2011 at 4:05 PM

ok - well the fact that the image is being requested due to a reference in a CSS file has nothing to do with the behavior of the rewrite.

The CSS file just tells the browser, "This is the background image" or whatever, and the browser makes a request to the server for the image. The server is not aware of what the browser might do with the image. It just delivers the image in response to the request.

I understand that you are not seeing any rewrites in those subfolders.

Did you download Fiddler and turn it on?  what requests did you see?

It would also be good to look at the IIRF logfile for ONE request for one of the images stored ina subfolder.


Apr 28, 2011 at 2:10 AM

Hi Cheeso, Found the bug !

My Rule apply to Images folder, not images. This is my bug. I didnt know that the rule is case sensitive. (:

Thanks for your help!

May 2, 2011 at 6:39 PM

Great, I am glad to hear you found the problem and got things working.

Good luck.