Internet technology hosted by Berkman Center

Relative links

When you link to an item on your own weblog, it would be convenient to use a relative rather absolute URL. For example:

Table 1
relative<a href="rss.xml">rss.xml</a>
fully-qualified<a href="http://weblog.infoworld.com/udell/rss.xml">
http://weblog.infoworld.com/udell/rss.xml </a>
relative vs fully-qualifed URIs

There are two advantages to the relative approach. First, it's more concise, so there's less typing and less likelihood of a copy/paste error. Second, it's more flexible. When you decide to relocate your blog to a new home -- it happens to everyone sooner or later -- you'd rather not have to chase down and adjust every internal reference.

For a while now, people in the weblog community have been discussing the use of an XML feature called XML Base:

This document describes a mechanism for providing base URI services to XLink, but as a modular specification so that other XML applications benefiting from additional control over relative URIs but not built upon XLink can also make use of it. The syntax consists of a single XML attribute named xml:base.

Figure 1 illustrates a simple RSS 2.0 feed that uses xml:base to specify the base URI for relative links.

Figure 1
<?xml version="1.0"?>
<rss version="2.0" xml:base="http://weblog.infoworld.com/udell">
<channel>
<title>Jon's Radio</title>
<link>http://weblog.infoworld.com/udell/ </link>
<description>Jon Udell's Radio Blog</description>
<item>
<title>relative URI test</title>
<link>http://weblog.infoworld.com/udell/2003/08/04.html#a766 </link>
<description>
(<a href="/index.html">relative</a>,
<a href="http://weblog.infoworld.com/udell/index.html">fully-qualified</a>)
</description>
</item>
</channel>
</rss>
sample RSS 2.0 feed with xml:base

This feed is currently not considered valid, and that's appropriate. The RSS 2.0 specification is silent on this issue, and RSS readers have not hitherto been advised to support xml:base.

Although it is not deemed valid, you can in fact subscribe to the test feed shown in Figure 1. Here's how three RSS readers handle the relative and absolute links in the sample:

Table 2
relativeabsolute
Radio UserLandhttp://localhost:5335/index.htmlhttp://weblog.infoworld.com/udell/index.html
SharpReaderhttp://weblog.infoworld.com/index.htmlhttp://weblog.infoworld.com/udell/index.html
NetNewsWirehttp://weblog.infoworld.com/udell/index.htmlhttp://weblog.infoworld.com/udell/index.html
How three RSS readers handle xml:base

[[[Although there is no requirement to do so, it appears that NetNewsWire implements xml:base as a best practice.]]] Although it appears that NetNewsWire implements xml:base in this example, it doesn't. Instead it uses the top-level link (rss/channel/link) which, in this example, is also http://weblog.infoworld.com/udell.

[[[We are inclined to recommend that all RSS readers honor xml:base when present.]]] We are inclined to recommend that RSS readers construe /rss/channel/link as the base by default, and xml:base (if present) as an override (if the base must differ from /rss/channel/link).

If that were to happen, weblog authors could -- after some transitional period -- begin using relative URIs for local references. Should they? The best practice in that case is debatable. Authors will, of course, always be free to choose between relative and absolute addressing. Depending on the content management system used, adjusting references when a blog moves might not be a problem, and absolute addressing will ensure that no RSS reader will be left behind. That said, if RSS readers embrace [[[xml:base]]] /rss/channel/link and xml:base, we would be inclined to recommend -- after a suitable transitional period -- that weblog authors take advantage of the feature.