Relative vs. Absolute Links

A lot of it depends on how you structure your site.

If you are linking to fixed resources, eg “/scripts/welcome.js”, then a root relative link is probably best, rather than trying to remember or compute how many levels up you need to go before heading into the scripts folder. On the other hand, if you’re linking to sibling resources, eg you have the images relevant to a page in the same folder as that page or in a child folder, then root relative links add an extra layer of faff and kerfuffle that you don’t need to bother with.

There’s no reason why you can’t have relative and root-relative links mixed within your site, depending on what works best in each case.

Relative links should be used for all the links within your site - that way the links will work both on your test server and the live one.

Absolute links should be used for all links to other sites.

With that combination your site can be moved anywhere and will still work (as long as the whoole site is moved).

I’ve heard that absolute links are better for SEO.

For example, instead of your home link being “index.php” it ought to be “http://www.mysite.com”.

Google “seo company” and take a look at the link structure used by the major companies.

The best solution is to have relative links…

B) What are the pros and cons to having absolute and relative links?

I would always use relative links. It is much less hassle, and it enables you to work locally and on a test server without having to change anything when you go ‘live’.

On some occasions, I will use links ‘relative to the root’, such as referencing images or other resources that are stored centrally rather than in the same folder as the document, but mostly I use the simplest form of relative linking possible.

The biggest advantage that absolute linking has (IMO) is that if someone downloads a page from your site onto their computer, on-site links will still work. From that point of view, it may be worthwhile making the “home” link an absolute link so that it will work in any context, but to be honest I don’t think it’s a big issue these days because people generally bookmark pages and link to them rather than downloading them.

Off Topic:

Llamas AND cowbells! It just doesn’t get any better…