Should I use a relative or an absolute link?

Written by Matt on 16 November 2009

Topics: Development tips

There is nothing more annoying then moving a website to a new domain name, and finding you, or somebody else, used a ton of absolute links.

Now you have to scour code and articles to fix them, since they are pointing to the old domain.  Is there a better solution?  Enter, relative links.

oookay, first things first.  What’s the difference?

A absolute link uses the entire domain name to point to your resource.  so if you want to include a url in your website, if you used a absolute link it would look like this.

absolute link

You can see there is a full url path included. (ht tp: // www.fancywebsite.com)

Now, a relative link is when the server already knows where the file or resource is. A relative link looks like this.

relative link

In this example you can see there is no full url such as a .com

Relative URLs are great if you move your site. With Joomla 1.5 you have very little changing to do in your configuration.php. You only have to change 2 values in that file and your site is moved. If you are in the habit of using absolute urls in your content, your website designs, or your images, now is the time to fully understand how cool relative links are, and how they will save you considerable amounts of time over the long haul.

Get notified about new tips & tricks for Joomla:

RSS

Click here to subscribe via RSS feed


subscribe

Click here to receive updates via email

Leave a Comment Here's Your Chance to Be Heard!

CommentLuv Enabled

Subscribe without commenting

Joomla! is the registered trademark of Open Source Matters, Inc and Joomlatips.com is not affiliated with or endorsed by Open Source Matters, joomla.org or the Joomla! project.