I've never seen
The fact that I have never noticed it in use on a modern production site (or any site) makes me leery of it, though it seems like it might have useful applications for simplifying links on my site.
The base tag appears to have some non-intuitive effects, and I recommend being aware of the outcomes and testing them for yourself before relying on
<base>! Since I've discovered them after trying to use the base tag to handle local sites with differing urls and only found out the problematic effects after, to my dismay, I feel compelled to create this summary of these potential pitfalls for others.
I'll use a base tag of:
<base href="http://www.example.com/other-subdirectory/"> as my example in the cases below, and will pretend that the page that the code is on is http://localsite.com/original-subdirectory
No links or named anchors or blank hrefs will point to the original subdirectory, unless that is made explicit: The base tag makes everything link differently, including same-page anchor links to the base tag's url instead, e.g:
<a href='#top-of-page' title='Some title'>A link to the top of the page via a named anchor</a>
<a href='http://www.example.com/other-subdirectory/#top-of-page' title='Some title'>A link to an #named-anchor on the completely different base page</a>
<a href='?update=1' title='Some title'>A link to this page</a>
<a href='http://www.example.com/other-subdirectory/?update=1' title='Some title'>A link to the base tag's page instead</a>
With some work, you can fix these problems on links that you have control over, by explicitly specifying that these links link to the page that they are on, but when you add third-party libraries to the mix that rely on the standard behavior, it can easily cause a big mess.
IE6 fix that requires conditional comments: Requires conditional comments for ie6 to avoid screwing up the dom hierarchy, i.e.
<base href="http://www.example.com/"><!--[if lte IE 6]></base><![endif]--> as
BalusC mentions in his answer above.
So overall, the major problem makes use tricky unless you have full editing control over every link, and as I originally feared, that makes it more trouble than it's worth. Now I have to go off and rewrite all my uses of it! :p
Related links of testing for issues when using "fragments"/hashes:
Edit by Izzy: For all of you running into the same confusion as me concerning the comments:
I've just tested it out myself, with the following results:
?querywould simply be appended to the specified
dir/other.htmlwould start at the
DOCUMENT_ROOTwith the given example,
/other-subdirectorybeing (correctly) treated as file and thus omitted.
So for relative links,
BASE works fine with the moved page – while anchors and
?queries would need the file name be specified explicitly (with
BASE having a trailing slash, or the last element not corresponding to the name of the file it's used in).
Think of it as
<BASE> replacing the full URL to the file itself (and not the directory it resides in), and you'll get things right. Assuming the file used in this example was
other-subdirectory/test.html (after it moved to the new location), the correct specification should have been:
– et voila, everything works as expected: