UC Santa CruzInstructional Computing
ITS Home About ITS IC Services News Tutorials Technologies About IC Help

Absolute and Relative URLs

Uniform Resource Locator, or URL, is a fancy name for address. Each file on the Internet has a unique URL.

The first part of the URL is called the protocol. It tells the browser how to deal with the file that it is about to open. One of the most common protocols you will see is HTTP, or Hypertext Transfer Protocol.

The second part of the URL is the name of the server where the file is located, followed by the path that leads to the file and the file's name itself, as illustrated to the right.

http://www.site.com/fun/file.html


Sometimes, a URL ends in a trailing forward slash with no file name given:

http://www.site.com/fun/


In this case the URL refers to the default file in the last directory in the path, which is a file named index.html. An equivalent URL to the one above would be:

http://www.site.com/fun/index.html


Absolute URLs

URLs can be either absolute or relative. An absolute URL shows the entire path to the file, including the protocol, server name, the complete path and the file name itself. An absolute URL is analogous to a complete street address; no matter where the letter is sent from, the post office will be able to find the recipient. In terms of URLs, this means that the location of the absolute URL itself has no bearing on the location of the actual file referenced. If you are referencing a file from someone else's server, you need to use an absolute URL. The URL's shown above are all absolute.

Relative URLs

Relative URLs are analogous to giving directions to someone such as "go down the hall and turn right." In other words, the directions refer to where you are starting from. In the same way, a relative URL describes the location of the desired file with reference to the location of the file that contains the URL itself.

For example, a relative URL for a file that is in the same directory as the current file (that is, the one with the link that points to that file) is merely the file name and extension, such as:

index.html


You create a URL for a file in a subdirectory of the current directory by placing the name of the subdirectory first and following it with a forward slash and then the name and extension of the desired file, as shown below.

/fun/file.html


To reference a file in a directory at a higher level of the file hierarchy, use two periods ( .. ) as shown below.

../images/image.gif


You can combine and repeat the two periods and forward slash to reference any file on the same server as the current file.

Why Should I Use Relative URLs?

Generally, you should always use relative URLs if you are referencing another page on your site. They make it easy to move your pages from a local system - such as your hard drive - to a server. Also, you will want to use relative URLs if you are planning on moving your pages onto CD for use in the classroom. Why? Because the protocol and server name in an absolute URL tell your browser to look for a site on the Internet. A relative URL just tells the browser to look for another file relative to the active file. Therefore, relative URLs work for both Internet and local pages (such as pages saved on a CD).


Please use the form below to tell us what you think of this page.


USCS Faculty Instructional Technology Center
2006-2007
Last updated 5/23/2007