Why Drupal doesn’t use relative paths in URLs

Submitted by Darren Oh on

After some hard-coded links stopped working when I moved a site to a subdirectory, I wondered why Drupal doesn’t use a <base> tag and relative paths for URLs. According to a 2007 article by Barry Jaspan, the <base> tag was removed in version 4.7 for reasons he did not know. So I tracked down the change in the commit log.

It appears that many search engine and proxy caches were ignoring the <base> tag, causing broken links. So the <base> tag was removed and Drupal started using absolute paths in URLs.

For URLs that are added to content manually rather than being generated by code, the Token Filter module enables authors to add a [site:url] token instead of hard coding the whole URL. For existing content that did not use a token to create URLs, the Pathologic module provides a text filter that rewrites URLs in text. So, if you keep hard-coded URLs out of your code, you can move your site to a subdirectory without breaking links.