Root relative path?


I need path help here!

Trying to get a stylesheet to load and I have the source set to my root relative path. ie: /home/account/website/styles.css

This does not work for me.

I can access the stylesheet from a absolute path such as: … but would prefer not to load all my files via a absolute path.

Same with images… cant seem to use root relative.

So what is the best way to load (css, images, js, etc…)?


it depends on where the file that’s calling the css file is. so if you have page.htm and styles.css both in account/website/ you wouldn’t need to call anything other than style.css but if the file was in website/etc/ you would need etc/styles.css if that makes any sense. there can be pitfalls to this though depending on what you are using to power your site. sometimes this makes absolute paths best. i have noticed sometimes using a cms of some sort navigating various pages sometimes would cause images and such not to load because the path would appear to be site/otherdir/etc so obviously a relative path link would fail.


That’s actually the absolute path, not relative, for the server. What you want is relative to the document root.

So Apache gets the document root from an absolute path setting (set in the panel, default: /home/USER/DOMAIN/), then everything is relative from that point.

document root: [font=Courier]/home/username/[/font]
relative path to css: [font=Courier]assets/css/stylesheet.css[/font]
absolute path to css (which won’t work from a browser but will work for commands issued on the server such as [font=Courier]cp[/font]: [font=Courier]/home/username/[/font]


So on that. My question is how to set the source path for images, css, js, etc,… in a header.php file that will be included on pages in sub-directories that will maintain a correct relative path?


Here is some clarification.

A server path is used for the filesystem on the machine running the web site.

A url-path is used in the URL requested by a web client.

These are two different namespaces, but they both have absolute and relative versions of paths.

Absolute paths start with something that indicates the top-most level of a hierarchy, for both server and url-paths this is / - and the name parts, separated by /, follow the path to the target.

Examples: an absolute server path will be /home/USERNAME/

And an absolute url-path will be /theme/styles.css (

So your header PHP code can certainly output HTML with URLs using an absolute url-path, and the same CSS file will be loaded despite where the PHP script is loaded from on the site. However when looking at your original post it appears you are saying that in your HTML you are using an absolute server path. That won’t work, HTML and HTTP don’t use server paths.