The thoughts, opinions and sometimes the rants of Mark Evans

Why Web Developers Are Right About Relative URL's

| Comments

I’ve just been reminded about a post from Joost de Valk (who authored the Wordpress SEO plugin I use on just about all the Wordpress sites I have built) about Why relative URLs should be forbidden for web developers.

It made me angry the first time I read it and now I’ve read it again its reminded me just how thin the argument is against using relative URL’s. Just a heads up that this post may wander into the realms of ranting (hence the soap box featured image).

His arguments might be fine for the small websites people build for themselves as a hobby that run on a single domain where they are happy to run the gauntlet of the white page of death or “this site is down for maintenance” when a Wordpress plugin upgrade goes horribly wrong, but not for anyone who calls themselves a ‘Web Developer’.

The world I live in the use of absolute URL’s can cause untold hours of lost productivity and frustration and I don’t know anyone who I would call a ‘Web Developer’ that would ever want to use them.

In this world we have separate development environments for each developer where plugins and theme upgrades can be easily checked and validated, then once the developer is happy, committed to a version control system and deployment onto a QA environment for testing, once testing is completed the code changes are pushed into the production environment for the world to see. The use of absolute url’s in this world is both unrealistic and wrong (IMHO).

Lets take a look at some of the arguments put forward

1. A completely indexed test environment

This is a pretty patronising argument, so we should be forbidden from having relative URL’s because we can’t be trusted not to allow them to be indexed by Google?

There are many ways to put together a development/qa/test environment that prevents this, for example all of my freelance development is done on a non internet facing webserver, where sites need to be seen by clients before release they are blocked from being viewed without a username / password so that Google is unable to access them. These should be pretty simple to do for any developer to implement and way simpler than having to go through and find all occurrences of a hardcoded domain in the database to update it before going into production.

2. Spider traps

First off I’ve never understood why people would use links like


rather than


these are pretty easy to generate automatically so that developers don’t make silly mistakes. This isn’t a very strong argument against the use of relative URL’s however, its an argument that sometimes people make mistakes, punishing everyone for them and suggesting the only fix is absolute URL’s everywhere is like Throwing out the baby with the bath water

3. Relative canonical URLs

This seems to be the same argument as in point 1. Relative canonical URL’s are valid and can be used but as with everything you need to understand what you are doing.

4. Protocol-relative URLs

Here I agree with Joost that using protocol relative URL’s is fine for CSS / JS but not for canonical url’s or links to other parts of your website. There shouldn’t every need to be a reason to serve the same content over both protocols (unless I’m missing something).

Joost also suggests some solutions to these problems.

1. Absolute URLs everywhere

Whilst in Wordpress you can control your site URL and home URL using wp-config.php by doing something like

Wordpress Site Configuration

Wordpress still stores the absolute URL’s to things within content and within serialised data, so even if you switch your domain in your configuration file, chances are you will still have links to your old URL embedded within content.

2. Canonical Redirects

I can see both pro’s and con’s to this approach however there may be occasions where having the same content on two different URL’s is required, so using the canonical URL’s meta tag is a way to prevent Google from punishing you for it. Where you have the same content on and then the use of 301 redirects is a simple solution for that.

I for one hope one day that the developers behind Wordpress take the bold steps of removing all instances where it stores absolute URL’s to anything (heck even make it a configuration option so they don’t break backwards compatibility) just give me (the developer) a choice. At the moment you make my life difficult and force me to find hacky work-arounds just to allow me to work in a structured way.

/rant over