Absolute or relative paths

P

Peter Smith

Hi all

I've noticed that some websites use absolute paths when linking to local
files, e.g. '/', '/style.css, '/images/logos/header.gif' etc., which has
the advantage that pages in subdirectories can use the same paths as
pages in the root, but also has the disadvantage that the site has to be
developed in the root folder (htdocs) rather than a subdirectory
(htdocs/myproject).

And some sites use relative paths ('images/logos/header.gif' or
'../images/logos/header.gif' if the page is in a subdirectory of the
root) which has the advantage that the site can be put in any directory
and the paths will work, but the disadvantage that calling functions
that create HTML or including chunks of HTML can be a problem because
the paths will need to change depending on the directory of the page
using the HTML.

Other sites seem to use a combination -- linking relatively to some
files but absolutely to others.

I'm never really sure which route to take. Are there reasons for
choosing absolute or relative paths that I'm not aware of?
 
J

Jim Moe

I've noticed that some websites use absolute paths when linking to local
files, e.g. '/', '/style.css, '/images/logos/header.gif' etc., which has
the advantage that pages in subdirectories can use the same paths as
pages in the root, but also has the disadvantage that the site has to be
developed in the root folder (htdocs) rather than a subdirectory
(htdocs/myproject).
I have found using the "absolute" method the easiest to maintain. It
makes it simple to have a local copy of the site for development then
upload the changes without having to modify the paths.
Putting multiple site in the same root is less than optimal for
management. Give each site its own root.
 
N

Neredbojias

Well bust mah britches and call me cheeky, on Mon, 08 Oct 2007 09:10:02 GMT
Peter Smith scribed:
I've noticed that some websites use absolute paths when linking to local
files, e.g. '/', '/style.css, '/images/logos/header.gif' etc., which has
the advantage that pages in subdirectories can use the same paths as
pages in the root, but also has the disadvantage that the site has to be
developed in the root folder (htdocs) rather than a subdirectory
(htdocs/myproject).

And some sites use relative paths ('images/logos/header.gif' or
'../images/logos/header.gif' if the page is in a subdirectory of the
root) which has the advantage that the site can be put in any directory
and the paths will work, but the disadvantage that calling functions
that create HTML or including chunks of HTML can be a problem because
the paths will need to change depending on the directory of the page
using the HTML.

Other sites seem to use a combination -- linking relatively to some
files but absolutely to others.

I'm never really sure which route to take. Are there reasons for
choosing absolute or relative paths that I'm not aware of?

If you're worried about it, why not use absolute urls?

(http://www.example.com/thisdir/thatdir/what.gif)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top