tags:

views:

52

answers:

2

Just a quick little thing, but i can't get past it.

So, say you would have in your html files references to images and css files, something like this: <img src="/img/myimage.jpg" />, and so on. Now, if you wanted to add a mod rewrite rule to map those addresses to something like /subset/img/myimage.jpg, how would you do that?

As far as i got, i couldn't overwrite paths that started with /. And while you're at it, would be nice if there would exist a rule that would do that mapping for all file requests.

Thanks!

Edit: And one more thing. There's also relative paths (generated by tinyMCE) that work like this "../../../../img/myimage.jpg". I'm not actually sure why those work, because those paths would get mapped somewhere way below public_html. Any help with those would be appreciated as well.

A: 

Ahh! Sorry for being stupid. You'll of course need to handle requests that are mapped to the document root AT the document root. You see i was working in a subdirectory.

The fact that paths work that are mapped below public_html or www still manages puzzle me. But i guess that extra "../" are just ignored and mapped to the document root.

JHollanti
A: 

Try this rule:

RewriteRule ^img/.* subset/$0 [L]

And now to your second question: Relative URIs are always resolved to a absolute URI before they are send to the server. So the client will resolve ../../../../img/myimage.jpg based on the base URI (see RFC 2396, 5.2. Resolving Relative References to Absolute Form). So the server will always receive an absolute URI path that it then can append to the document root path to map the requested URI path to the file system.

Gumbo
And i'm guessing that it'll strip out excess "../" ?
JHollanti
Yes, useless `../` are stripped out. Try it for yourself: http://example.com/../../../../../../../../.
Gumbo