Whenever you type in an <a href=”…”> tag, there are a number of different ways to write in your link. The location that you give can be:
- Absolute: “http://ellisweb.net/” – this will work from any page, and will always point to the proper destination. These can get annoying though. After all, who wants to type out the full html for every page, especially when they are pages on your site
- Relative: “photos.html” – this will point to the given file, residing in the same directory as your current file. This works as long as you don’t change your directory structure. Ever. Additionally, this can be a bit confusing and easy to mess-up sometimes, especially when you have links like “../../../Articles/123.html”.
- Relative to the Root: “/photos.html” – this is kind of in between the first two types. It only works on your own site. It identifies the exact location of a file, but identifies the location relative to the root directory of your website. Thus, as long as the photos.html file stays in the same location, this link will always work, regardless of the point of origin. Furthermore, if someone hovers over the link and copies it, it will copy the full path (ie: http://example.com/photos.html).
If you think that the location of a page will change, the third option above seems to have become an acceptable way to link to pages. (And if you know for sure that your site directory structure will never change, then there is nothing wrong with relative links). However, with the proliferation of RSS syndication, using either type of relative link can lead to unforeseeable outcomes.
For example, in Daily Grind 853, Mike has a sentence at the top: “Well, thanks to the site redesign, there’s now a page full of them.” (he is referring to site logos). In this sentence, the words “page full of them” are linked to http://www.larkware.com/linking_images.html. At least, that is the way they are linked if you look at the site directly.
I subscribe to the RSS feed for the Daily Grind, so I initially read this through my Bloglines account. When I went to click on this link, I ended up at http://bloglines.com/linking_images.html, giving me a “404 Not Found” error. Why did this happen?
Examining the source for this page, the link tag is defined as <a href=”../linking_images.html”>. So what happened? Mike used a relative link that works perfectly on his own site. However, when Bloglines (and presumably other online newsreaders as well) served this out, they just published the relative link as it was in the published feed. This caused the incorrect linking situation that I experienced above.
(Sorry to pick on you Mike, I have seen this happen from other sites too. Yours is just the one that prompted me to write this).
The moral of the story: If you publish an RSS (or ATOM) feed, and you want to make sure that your readers will always be able to get through to your links, no matter where they are reading your content, stick with absolute linking.
(And to any programmers working for Bloglines or their competitors – for the sake of your users, could you guys stick some logic into your display that automatically converts relative links in feeds into absolute links?)