Search code examples
htmlurlmod-rewritehref

Relative and Absolute Addresses


My question regards relative and absolute addresses.

I have over the years built a framework, which all my php websites are built on.

Every single page is loaded in the top level "index.php" file. This is cool, because I never struggle with paths to resources. Every single resource, at every single level of the system is referenced from the top level index file, so the paths are always similar:

ie (img src="images/sprites/xxxxx.jpg" ) from every single page in the system.

But now I've ruined it by introducing mod_rewrite. mod rewrite seems to have confused the path system I've been using. So it's time for me to update the paths. Stylesheets and images no longer load.

How should I fix this? Is it true that relative paths are loaded faster than absolute? isn't there some way in PHP to find the root of your server file system assign it to a $var and then prepend that $var to image paths? Is that any faster than just referencing my images & Stylesheets as "http://site.com/images/xxxx.jpg" ?

I have alot to learn now. Any input please


Solution

  • Just add a / before the images directory

    img src="/images/sprites/xxxxx.jpg"
    

    it's the same as:

    http://site.com/images/sprites/xxxxx.jpg