EverWeb Widgetbox

Relative & Absolute File Paths

Relative File Paths

A relative file path is the URL to any file contained in the website's root folder from any other file in the same root folder. A relative path from a page in one directory to a page in another would look like this...

../directory-name/page-name.html

... where page-name is the name of the file that is being linked to and directory-name is the name of the containing folder.

These differ from the absolute path which starts with the domain name ...

http://www.domain-name/folder-name/page-name.html

Absolute paths will not work unless the file is upload to a server.

Relative paths do not need this part of the URL - http://www.domain-name/ - and their main advantage is the fact that the file will load faster than one in the same website which is referenced using an absolute path.

Relative File Path Examples

The ROOT directory is the folder which contains all the files and folders for the website

If two pages are in the root folder or in the same directory folder, the path inserted into the hyperlink is simply...

page-name.html

If the page containing the hyperlink is in the root folder and the page the hyperlink points to is in a directory, the path is..

directory-folder-name/page-name.html

When the page containing the hyperlink is in a directory and the page the hyperlink points to is in the root folder, the path will be...

../page-name.html

The ../ creates one backward step out of the folder.

When the page containing the hyperlink is in a directory and the page the hyperlink points to is also in a directory, the path will be...

../directory-folder-name/page-name.html

... so the path backs out of one folder and then goes into another.

Absolute File Path

An absolute file path is the URL to a page or file from anywhere on the world wide web. It includes the domain name like this...

http://domain-name.com/directory-name/page-name.html

Although an absolute URL can be used to interlink pages with the same root folder. it's not very efficient since it creates more server requests and eats into the monthly bandwidth allowance of cellular mobile device users.  

File Names

It's very important to realise that every file used in a website forms part of a URL. The file name must NOT contain any spaces or special characters such as an apostrophe.

File names should be descriptive for SEO and the words should be separated by a hyphen rather than an underscore so that they are easier to read by humans. The search engine spiders don't care if you use underscores but they tend to become invisible to humans when the hyperlink itself is underlined.