Relative and absolute pathnames

The like above is "index.php" and this linked to a page within this directory (html). If we wanted to link to the same page but with the full url, then it would look like this "/programming/html/index.php". This is an absolute pathname (where the link is linking to) and the "index.html" is a relative pathname. In relative pathname, the browser will look for the file name within the directory. But, relative pathname can link to other pages on the website that is not in the same directory (folder) too. We will explain it later on the page.

Relative pathnames point to files based on their locations relative to the current file. A pathname can include going up directories, going down directories, going back to the main directory, or going down and then up, etc. There are endless possibilities. Inorder to specify relative pathnames in linkes, you will need to use UNIX-style pathnames regardless of the system that you are hosted on. So directory or folder names are separated with slashes (/), and you use two dots (..) to refer to the previous folder or the folder before this one which is above this directory (for our site, the current directory is "html", if we used the two dots with a slash (../), then we would go back to "programming").

PathnameWhere does the link go
Example codeExample outcome
href="file.html"file.html is located in the current directory
<a href="index.php">Home</a>Home
href="files/file.html"file.html is located in the directory files and the directory is located in the current directory
<a href="files/index.php">Does not work</a>Does not work
href="files/morefiles/file.html"file.html is located in the morefiles directory which is located in the files directory which is located in the current directory (of course you can even open files that are within more directories, but we will not bother explaning here)
<a href="files/morefiles/index.php">Does not work</a>Does not work
href="../file.html"file.html is located in the directory one level above the current directory
<a href="../index.php">Programming</a>Programming
href="../../file.html"file.html is located two directories above the current directory (you can go back as many directories as you want and need, just add ../)
<a href="../../index.php">Mysite101</a>Mysite101
href="../files/file.html"file.html is located in the files directory which is one directory above the current
<a href="../css/index.php">CSS</a>CSS
href="../../files/morefiles/file.htmlfile.html is loacted two directories above the current in the morefiles directory which is located in the files directory (like previously mentioned, you can go back and forward as many directories as you need and want, there are no limits)
<a href="../../downloads/imageediting/index.php">Does not work</a>Does not work
a href="/file.html"file.html is located in the main directory (the directory is the first directory, which is where the first page of your website is located in, it's a shortcut to the main directory, it is also absolute pathname)
<a href="/index.php">Mysite101</a>Mysite101

Absolute pathnames point to files based on their absolute locations on the file system. Unlike relative pathnames it does not describe the link by describing its location relative to the current page, it starts at the top level of your directory hierachy (which is your main directory). It will then work downward through al the intervening directories to reach the file. Absolute pahtnames always begin with a slash (/). An example would be <a href="/">First page</a>, This would lead the user to the first page of the website which is the index page of the website. You can also add the index.html in it, but it is not mandatory. If you don't add anything and just use a slash (/), then it is assumed that you are linking to the index page. If you need to, you would then add directories after the slash if you are linking to a file that is not in the first directory and type in the file name.

Absolute pathnames are very self explanatory, so we will not explain much further. Below is an example of an absolute pathname:

<a href="/programming/html/">HTML</a>

You will get:

HTML

You can use either relative pathnames of absolute pathnames on your website, but to link to another website or another page on another website, then you will have to write out the full url or url of the remote address/file. Let's pretend that we want to like to http://www.google.com, google is not located on our website, so will have to write out the URL to the site and it is called a remote address/file because it is not located on our site. The example to link to google would look like this:

<a href="http://www.google.com">Google</a>

The outcome:

Google

Let's take a look at the structure:

There are many places that you can add links, just use the <a> </a> tag to add the link. You can add links on bullets, lists, pictures, titles, etc.

Copyright Brains That Work .
Theme by Pool theme design by Borja Fernandez. ^Top^