Forum Moderators: phranque

Message Too Old, No Replies

.htaccess - messing up css + images

         

area5one

9:09 am on Sep 20, 2009 (gmt 0)

10+ Year Member



Hi guys,

I'm trying to convert URL's such as

[svc2c.naty.cc...]

into

[svc2c.naty.cc...]

The Code:

RewriteRule ^([A-Za-z_0-9]*)/([A-Za-z_0-9]*)$ index.php?n1=$1&n2=$2 [L]

With this the css and images don't work, but I can see the html. Any ideas why?

jdMorgan

3:24 pm on Sep 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Likely because you have linked to your css and images using page-relative links, of the form <img src="images/logo.gif">.

Remember that it is the browser that resolves relative links on the page to the absolute URLs that must be used to fetch the requested object. So a link like that will be resolved to "http://svc2c.example.com/about/images.logo.gif" according to the rules of page-relative URL-resolution (strip 'page' off of current 'address bar' URL to get the 'directory,' then add the relative URL-path from the on-page link).

The best fix is to use server-relative links or canonical URLs, as in <img src="/images/logo.gif"> or <img src="http://www.example.com/images/logo.gif">.

[added] Note also that you could improve the performance of your rule by about 30% with one simple change:


RewriteRule ^([[b]a-z[/b]_0-9]*)/([[b]a-z[/b]_0-9]*)$ index.php?n1=$1&n2=$2 [[b]NC,[/b]L]

(Use the [NC] flag to make the character-comparison case-insensitive.) [/added]

Jim