|
Relative and absolute pathnamesThe 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").
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: 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: 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. |