Forum Moderators: phranque

Message Too Old, No Replies

mod rewite makes nice URI's but can't find css

         

roobottom

10:57 am on Sep 20, 2006 (gmt 0)

10+ Year Member



I've written a mod_rewrite to rewite urls in the format

http://www.example.co.uk/pp/product/name/idno to
http://www.example.co.uk/pp/info.php?product=name&id=idno

like so...

# BEGIN UpdateURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /pp/
RewriteRule ^product/([A-Za-z0-9-]+)/([0-9]+)/?$ info.php?product=$1&id=$2
</IfModule>

which works, but typing in the search-engine friendly url, the page can't find any of the linked files (style sheet, images, etc..)

<snip>

Can anyone see what I'm doing wrong? Thanks!

[edited by: jdMorgan at 12:26 pm (utc) on Sep. 20, 2006]
[edit reason] Examplified. No URLS, please. See TOS. [/edit]

jdMorgan

12:36 pm on Sep 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The most likely cause is that you've used page-relative links to those resources. Remember, it is the client --the browser or search engine spider-- that resolves relative links. So, if you use an internal rewrite (as opposed to an external redirect), the client is unaware that the page URL has changed, and will construct URLs for the images, CSS, and external JS files referenced on the page by using the current page URL that shows in the address bar, merged with the value of the page-relative link, as it always does.

The solution is to do one of two things:

1) Use server-relative links or canonical links instead of page-relative links (e.g. use <img src="/images/widget.gif"> or <img src="http://www.example.co.uk/images/widget.gif"> instead of <img src="images/widget.gif">

2) Modify your rewrite rules so that the reference URLs on a page are rewritten in the same way as the page URL itself.

It's easy to verify whether this is the problem: Look at your server error log and access log to see what path was used when the image/CSS fetches failed.

Jim

roobottom

4:08 pm on Sep 20, 2006 (gmt 0)

10+ Year Member



Thanks, yes, that is the problem!

How do I update my mod_rewrite to re-write the rules for the css and the images too?

Sorry to be a pain, but until today I was a mod_rewrite virgin.

Thanks!