0% found this document useful (0 votes)
524 views3 pages

Absolute and Relative Url

An absolute URL directly specifies the exact location of a file on the internet using the full path, including the domain name. It is unique and independent of any other files or directories. A relative URL specifies the location of a file relative to the current file's location, and can only be used to link to files on the same server. Relative URLs are shorter and make website maintenance and transferring easier, while absolute URLs are useful if planning to change a file's directory location.

Uploaded by

Jyoti Bhanot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
524 views3 pages

Absolute and Relative Url

An absolute URL directly specifies the exact location of a file on the internet using the full path, including the domain name. It is unique and independent of any other files or directories. A relative URL specifies the location of a file relative to the current file's location, and can only be used to link to files on the same server. Relative URLs are shorter and make website maintenance and transferring easier, while absolute URLs are useful if planning to change a file's directory location.

Uploaded by

Jyoti Bhanot
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Absolute URL

In addition to several other meanings, the word absolute, in English, means "not
dependent on anything else". It also means "free from doubt".
An Absolute URL is, thus, something that is independent or free from any
relationship. When you use an absolute URL, you point directly to a file. Hence,
an absolute URL specifies the exact location of a file/directory on the internet. It
also follows that each absolute URL is unique, which means that if two URLs are
identical, they point to the same file.

For example:
http://www.webdevelopersnotes.com/images/email.gif specifies an image file
email.gif located in the images directory, under www.webdevelopersnotes.com
domain name.
Similarly, the absolute URL of the document you are viewing is
http://www.webdevelopersnotes.com/design/ relative_and_absolute_urls.php3 which
is a page in the directory called design on this web site.

Relative URL
A relative URL points to a file/directory in relation to the present file/directory.

Let us understand relative URLs through a small exercise.


Look at the two URL above. We want to include (display) the image file email.gif
stored in the images directory of www.webdevelopersnotes.com domain on this
(relative_and_absolute_urls.php3 stored in the design directory) page.
There are two ways to do this. We can either refer to it using an absolute URL or
use a relative URL. The <img> tag for this image display will be as follows:

Using an Absolute URL in an <img> tag

<img src="http://www.webdevelopersnotes.com/images/email.gif"
width="..." height="..." />

Using a Relative URL in an <IMG> tag

<img src="../images/email.gif" width="..." height="..." />

The absolute URL is straight forward but in the relative URL you'll notice that I
have refered to the image with ../images/email.gif. In order to understand the
relative URL, let me tell you about the directory structure of this web site.
This web site has several sections and the files and web pages for each section
have been segregated into different directories. This helps me to keep things
organized and uncluttered on the web site. Under the document or server root
directory (the main directory of the web site), I have a directory called images
which stores all common images used on the pages of this web site. The image
email.gif resides in this directory. I have another directory called design which is at
the same level as images i.e. it is also in the document root directory. This design
directory contains the files and web pages for the "Web Page Design" section of
this web site. Diagramatically, the scenario can be represented as:

Now to access email.gif file from relative_and_absolute_urls.php3 page using a


relative URL we put ../images/email.gif in the SRC attribute. We, thus, instruct the
browser to first go one level up (i.e. to the document root) and then move to the
images directory and pick up the file email.gif. The two peroids (..) instruct the
server to move up one directory (which is the root directory), then enter images
directory (/images) and finally point at email.gif.

Which URL type to use - Absolute or Relative?


This is one of the most fundamental questions in web site design.
I have always prefered relative URLs as they help in web site maintenance. Also,
it's easy to transfer a web site from one domain name to another. If you had used
absolute URLs in all links and SRC attributes, you'd have a difficult time updating
each link on each page. With the use of relative URLs you have no such
problems. Also, relative URLs would be shorter than absolute URLs and hence
the file size of the web page would reduce (click know more about optimizing web
pages) if you use the former.
Absolute URLs too have their advantages and are especially helpful, if you want
to plan to shift a page on your web site from one directory location to another. (I
am not sure why you would want to do this, but if you do, absolute URLs would
be helpful in such cases).

Finally, I have not known of any server performance benefits with the use of a
particular URL type.
What is the difference between an absolute and a
relative URL?
An absolute URL typically takes the following form:

protocol://hostname/other_information

The protocol is usually http://, but can also be ftp://, gopher://, or


file://. The hostname is the name of the computer. For example, the
hostname of Indiana University's central web server is www.indiana.edu. The
other_information includes directory and file information. You must use
absolute URLs when referring to links on different servers.

A relative URL doesn't contain as much information as an absolute URL does.


Relative URLs are convenient because they are shorter and often more portable.
However, you can use them only to reference links on the same server as the
page that contains them. Relative URLs can take a number of different forms.
When referring to a file that occurs in the same directory as the referring page, a
URL can be as simple as the name of the file. For example, if you want to create
a link in your home page to the file foobar.html, which is in the same directory
as your home page, you would use:

<a href="foobar.html">The Wonderful World of Foobar!</a>

If the file you want to link to is in a subdirectory of the directory the referring page
is in, you need to enter only the directory information and the name of the file. So
if foobar.html were in the foobar subdirectory of your www directory, you
could refer to it from your home page by using:

<a href="foobar/foobar.html">The Wonderful World of


Foobar!</a>

If the file you want to link to is in a higher directory than the referring page, use
.. , which means to go up a directory. For example, to link from foobar.html
to home.html, which is in the directory above, you would use:

<a href="../home.html">Go back to my home page</a>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy