Linking to other sites on the Internet is pretty simple. You just type the link code and plug the site's address into it. Linking to another page on your own site can be done the same way but there is a better way. There are some shortcuts you can use to make your code writing shorter.
When you are creating your site you usually have different folders in your file manager. You may even have folders inside of folders.
These are a great way to organize your site so that you always know where to find a specific page. The problem with doing it this way is that it makes it more difficult to link to the pages.
If all your pages were in the same folder, all you would have to plug into the link code is the name of the page with the extension. You wouldn't have to use the whole URL:
<a href="file.html">Page Name</a>
instead of
<a href="http://www.hostname.com/username/file.html">Page Name</a>
Since you have decided to use a variety of different folders to organize your site you can only use that example if you are linking to pages that are in the same folder. What if you want to link to a page that is in another folder?
Lets say your folder structure looks something like this:
mainpage.html
|
folder:january
/janfirst.html
/jansecond.html
|
folder:february /febfirst.html
- folder:firstweek
/feb2nd.html
Let me explain what this means, for those of you who don't know.
The url for the page feb2nd.html would look like this: http://www.hostname.com/username/february/firstweek/feb2nd.html.
The url for the page febfirst.html would look like this: http://www.hostname.com/username/february/febfirst.html.
The url for the page mainpage.html would look like this: http://www.hostname.com/username/mainpage.html.
The url for the page janfirst.html would look like this: http://www.hostname.com/username/january/janfirst.html.
Get the idea? Now we are ready to use some shortcuts for these same pages.
Let's say you were wanted to add a link to janfirst.html from jansecond.html. Your link would look like this: <a href="janfirst.html">All you have to use for the URL in this case is the page name. This is because they are in the same folder.
If you wanted to add a link to mainpage.html from janfirst.html you would do this: <a href="../../mainpage.html">
The dots mean that you want to go back one folder. So, if you want to link to mainpage.html from janfirst.html you would only need one set of dots, like this: <a href="../mainpage.html">
If you start your URL with a slash you will be able to start your link at that position: <a href="/january/janfirst.html">
NOTE: These shortcuts may not always work on some hosting services. I know this from experience. I don't know why this is.
previous post