tags:

views:

41

answers:

1

I'm struggling with a mod_rewrite problem that involves .css files that are dynamically served by a "program" that reference images. I say "program" since the the tech stack is a bit obscure, but just insert your favorite technology there [perl | php | java].

The CSS file is referenced from the page using the following URL:

http://server/dir/subdir/file-program?site-id=1234&fname=stylesheet.css

The content of the CSS include image references like the following:

background-image:url('hello.png'); 
... 
background-image:url('world.png');

The browser interprets these references as /dir/subdir/*.png.

What I want to do is rewrite all of those requests using the URL of the referrer so they end up looking like:

http://server/dir/subdir/file-program?site-id=1234&fname=hello.png
http://server/dir/subdir/file-program?site-id=1234&fname=world.png

Note that the site-id is variable, so I would really need to reference the referrer to pick up the whole query string. Sorry I left this out of the original post.

Put differently: Any image references that comes from ...file-program...*.css should be rewritten to use the URL (including query string) of that CSS, just substitute the image file name for the css file name.

Any help would be greatly appreciated.

+1  A: 

I can't make any promises, but give this a shot:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s [OR]
RewriteCond %{REQUEST_FILENAME} !-l [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/dir/subdir/(*.)$ /dir/subdir/file-program?fname=$1&referer=%{HTTP_REFERER}
RewriteRule ^/dir/subdir/file-program?fname=(.*?)&referer=(*.)siteid=([0-9]+) /dir/subdir/file-program?fname=$1&siteid=$3
Jordan Ryan Moore
Jordon,Looks like I left out a key detail and that is that the site-id is variable, so I would like to reference the referrer (the .css file) to pick up the query string.
Tyler