Relative URL vs Absolute URL – An Explanatory Guide

The debate about the superiority of relative URL and absolute URL seem far from being ended. It a debate that has been on-going for years now and i would like to talk about it again.
First off, let’s take a look at the definition of both term.

  • Absolute URLs

    These are URLs that contain both the domain name and directory/page path. A good example is http://yoursite.com/category/file.htm.
    That’s an Absolute URL

  • Relative URLs

    These are URLs with just the path excluding the domain name. Example is category/file.htm or /category/file.htm though the latter is preferable.

Most web developer, have split decision and often argue about the effect and relevancy of both relative and absolute URLs with some favoring one to the other.
Though they both have their pros and cons, it up to you to decide which one you prefer. Am going to try outline the pros and cons of both term.

  • In developmental environment
    When building a website in a development environment: such as local or staging server, it easier and recommended you use relative URL in it. I don’t see a possible use of absolute in this instance because it won’t work.
  • Movement of website
    Relative URL make the transfer of a web project from a local server to a web server easy and smooth ‘cos, you don’t need to edit and change the URLs.
    Not only that, if you want to move your website to a new domain or subdomain/folder, relative URL do come in handy. Using absolute URL in this case, would require you changing all the href attribute to your new domain name/ip address. This is to me tasky.
  • On-page code size
    Personally, i don’t think this a genuine reason for you to stick out your neck for relative URL. I have never heard that increase amount of on-page codes have any adverse effect – subject to debate.
  • Effect on scrappers job
    If you’re using relative URLs, then you are making the job of scrapper website easy, because when they steal your website content, the relative URLs on it adjust to the scrapper domain name. Example: assuming the below html code is your website content

    This is my website content with my internal link relative. <a href=”/contact.htm”>contact me</a>. My content ends

    Note: when you view the above html code via a webrowser, and you click the contact me link, the URL becomes http://yoursite.com/contact.htm.
    When a scrapper scrap your web content, you agree with me that the relative URL adapt to the scrapper website domain name or ip.
    This is where absolute URL come in handy, because it deter scrappers (since they will have to replace all base href values).

  • Susceptibility to hacking
    I have heard in many webmaster forum and blog that absolute URL are said to be safer that relative in hacking. I don’t know how true this it.
    Some web programmer think it an old yarn that was born out of ignorance, because they’ve heard the words “hacker” and “relative path” use in same sentence so often, that they became afraid of relative URL. I think they may be right on this – subject to debate.

Most people make reference to a statement made by google’s Vanessa Fox in defending their choice of using absolute url -: We also suggest you link to other pages of your site using absolute, rather than relative links with the version of the domain you want to be indexed under. For instance, from your home page, rather than link to products.html, link to http://www.example.com/products.html. And whenever possible, make sure that other sites are linking to you using the version of the domain name that you prefer.
For me, this is not a good enough reason for me to ditch the relative url.

Conclusion
I still prefer the relative url in web development with a html base tag at the header. But if you are a blogger or freelance writter, i urge you to use absolute url in your articles when making references.
If you have a contribution or objection, why not comment below, so we hear your view.

Don’t miss out!
Subscribe to My Newsletter
Invalid email address