[Zope-Coders] base href madness

Chris McDonough chrism@zope.com
Wed, 28 Nov 2001 02:04:38 -0500


I did a little research into when and how and if the base href tag
needs to be inserted into a document.

First of all, the purpose of this thing is to provide a base for
relative URLs within an effected HTML document.  You can do this:

<html>
<head>
  <base href="http://www.microsoft.com/">
</head>
<body>
<a href="foo">LINK!</a>
</body>
</html>

When you hover over the LINK!, and if your browser is sane, you'll see
that it points to http://www.microsoft.com/foo.

Now, the folks who standardize HTTP figured that they could also help
out when it came to giving folks a way to spell the base URI of the
content returned in HTTP/1.1 (there is no way to spell this outside of
HTML in HTTP/1.0).  The mechanisms they came up with allow a compliant
server to specify the base URI to the client without needing to
actually munge HTML.

They first came up with the "Content-Base" header as a part of
HTTP/1.1.  This was a very simple directive that said, "use this as
the base URI if there is no BASE tag".  Nobody except Mozilla and Lynx
seems to have ever implemeted a client that uses it, however.  They've
since removed this header from the spec.  It still works under Mozilla
and Lynx, and probably others, but ot never worked under IE.

No worries, though, because they also provide "Content-Location",
which lets you specify an "alternate" location for the entity
represented by a URI.  So, for example, you'd be able to set the
content location of a containerish thing named "foo" to "foo/" by
setting this header in a response.  The spec goes on to say that "the
value of Content-Location also defines the base URI for the entity"
though it also notes that this value can can be overridden by a BASE
tag in the docment itself.

But, as the world goes, nobody, not even Mozilla, adheres to the
behavior noted in the spec.  Setting a Content-Location header in a
response to IE5.5 or Mozilla has no discernable effect on the URLs of
linked elements.

So, for now, we either need to keep munging HTML by setting a BASE tag
or cause Zope to redirect to the "right" URL when we notice that
someone has requested an object through a name that would cause the
base URI to be incorrect for things that are rendered within the HTML
of the object representation.  Redirecting is way too expensive for
high-traffic installations to even consider, IMHO, so I think we just
continue to munge.

----------
Chris McDonough                           Zope Corporation
http://www.zope.org                    http://www.zope.com

""" Killing hundreds of birds with thousands of stones """