by Dinesh Thakur Category: HTML

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 it 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 below:

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

protocol // Server Name / Path / File Name

 Sometimes, a URL ends in a trailing forward slash with no file name given, as below. 

"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 from someone else's server, you need to use an absolute URL. The URL's 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 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.

Inside the current folder .... “fun/file.html” ...there is a folder      ... that contains called "fun" ...          a file named "file.html" ...

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

The folder that contains the current folder .. , ... contains ... “../images/image.gif” ... a folder          ...a file called "images" "image.gif" that contains ...

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



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.