You've no doubt heard of both relative and absolute links, and probably know what they mean too - but just how much do you know about them?
First of all, there are two types of links - internal and external.
- Internal Links
- An internal link is one that points to another page on the same site.
- External Links
- An external link is one that points to another site, and quite often by a third party.
Internal links are most commonly identified by them being relative links - they do not contain the full URL to where the page is, but instead just contains a path relative to where the page being viewed is. So for example /home.html would be relative to the root of the site, meaning that it would look for home.html in the root. Using ../ has a similar effect but only looks one level above.
To change where these paths are relative from we can use a metatag known as BASE. I've referred to this as a metatag rather than a HTML tag as it's one that lives in the HEAD section of your page. So in there we might have:
<base href="http://www.newearthonline.co.uk/photos/" />
This example when used would mean that all relative links on that page are not relative to the root of the site, but instead relative from the "photos" folder. So if a page existed in /example/test/test.html and had a link to ../index.php or /index.php then the first one would be pointing to index.php in the root of the site (one level above the photos folder) and the other would be pointing to index.php in the photos folder.
Now an absolute link however could be used to point to either another third party website, or could be used to point to a page without having to take a possible base tag into account.