Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite and linked css and image files

         

ajkimoto

4:52 pm on Mar 31, 2006 (gmt 0)

10+ Year Member



Greetings,

I have a question concerning mod_rewrite and linked css pages and images. If I set up the rewrite rule to change:

mysite.com/index.php?tm=04&lm=02

into

mysite.com/research/02.htm

I lose the link to my css stylesheet and to image files. I could just change all the relative urls to fully qualified urls, but was hoping for another solution. This is probably a trivial question, but I am very new to mod_rewrite...

Thanks,

ajkimoto

jdMorgan

3:27 am on Apr 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can either change those broken links from page-relative links to canonical or server-relative links, or rewrite the requests for the URLs in those links.

Canonical: <img src="http://www.example.com/logo.gif">
Server-relative: <img src="/logo.gif">

It helps to keep in mind that it is the browser that resolves relative links. Once you focus on that fact, resolving this kind of problem is quite a bit easier.

Also it helps to keep in mind that your are rewriting the static URL request to a dynamic internal filepath; That is, mod_rewrite changes the filepath that a URL references, and it does so just after the HTTP request is received, and before any content-handlers or scripts are invoked.

Jim

ajkimoto

2:05 pm on Apr 3, 2006 (gmt 0)

10+ Year Member



Okay, this is as I suspected--just wanted to make sure that I wasn't missing some other solution.

Thanks Jim!

Andrew