linking web pages

  • Thread starter Der Alta
  • 4 comments
  • 446 views

Der Alta

Official GTP Bouncer
Staff Emeritus
9,209
DerAlta
I'm not sure how to ask this question, so I'll start with the situation.

Not sure how many of you have seen my compendium website, but it contains my entire trip through GT3 (0-100%) in pages.

What I'm wondering is that I currently have each page "hard" linked to the physical site on the website. If I "mouse over" a link it shows up as www.deralta.net/compendium/pagexxx.html.

This means that when I'm revising it on my computer it always wants to link to the web to find the targeted page.

What should I change this to so that it links to the one in the same folder that it resides in?

<a href="http://www.deralta.net/compendium/page062.html">

Thanks

AO
 
This should do the job, as long as it is in the same directory both on your server and on your computer.

Code:
<a href="page062.html">
 
Thats what i do.

Seen as all the pages of my site reside on the same server, i don't type 'http://gtsc.netfirms.com/gt3stats.htm', rather just 'gt3stats.htm'

It's much easier and saves a lot of time. :)
 
The only time you need to do http://blah.blah.blah is if you need to link to something under a different sub-account, different domain, etc. I only have http:// included in my links for my forum(since I have a second account dedicated to that because of its install size) and for external sites that I think are good and relevent.

Also, you could try using targets, I think they were... I've only used them once, and that was when I still used a Netscape program to make my websites. But basically it allows you to have a link go to a specific place in a page instead of just starting at the top of the page.
 
OK, what's being described here is the difference between absolute paths and relative paths.

You should use a relative path wherever possible, because this allows you to move files around in the directory structure more easily. It also allows you to cope with multiple domain names accessing the same physical file.

To use relative links effectively, you need to know that a period indicates the same directory. So
Code:
href="page.htm"
is the same as
Code:
href="./page.htm"
.

Always use forward slashes for directories, because most of the world's web servers are running on some flavour of UNIX, which uses forward paths. Most likely your web server will be able to cope with backslashes, but you don't want to count on that.

Also, you need to know that two periods signifies the parent directory. Let's say that you have an index page, and all your race pages are held in in a directory, called "races".

If you linked straight to race 47 from the index, you would use
Code:
<a href="./races/page47.htm">Race 47</a>

You can drop the initial period, but it's best practice to leave it in place.

If you wanted to put a "back to index" link at the bottom of each page (and I would suggest you do look at doing something like this), then you would use
Code:
<a href="../index.htm">Back to Index</a>

This relative linking is quite flexible. You can navigate up and down in the tree by combining the periods and directory names. So if you had an image that was held in an images directory at the same level as the races directory, you could link to that image from a race page by combining a "parent" command and an "images" command thus:
Code:
<img src="../images/pic.gif">

You would use absolute links, as rjensen11 says, when you wish to access pages on another domain.

However, rjensen11's advice on targets is not right and is a slight red herring in this instance. You're using frames at the moment, so you should have sussed targets out!
 
Back