Absolute URLs vs Relative URLs


Absolute URL - An absolute URL contains all the information necessary to locate a resource. In context to the Spark Pay online stores system, it typically begins with http:// or https:// . For example, http://sparkpay.com is an absolute URL.

Relative URL - A relative URL typically contains only the path to a specific file. In context to the Spark Pay online stores system, these typically begin with a forward slash. The forward slash basically tells the browser to go to the domain of the site. For example, /images/img.jpg is telling the browser to go to the domain, then look for the images folder, then find the img.jpg file inside the images folder. So if this were on sparkpay.com, it would automatically change to http://sparkpay.com/images/img.jpg in the browser window.

Why does this matter?

A benefit is if the web domain changes, you don't have to manually change all the URLs. For example, lets say your site is http://site1.com/ and you have an image located at /images/image.jpg. If you link the image with http://site1.com/images/jpg, then you will have to update this link if the domain changes. However, if you have it set as /images/image.jpg , then you won't need to update the URLs whenever the site changes, since the beginning forward slash is saying "go to the domain of the site". 

When should I use relative URLs?

You should use relative URLs whenever you are linking to somewhere on the same site. If you are linking to another site, then you will want to use an absolute URL. 

How helpful was this article?
Number of questions: 0