Tutorial 25: The Care and Feeding of Hyperlinks, Part I - HTML with Style | 4 | WebReference

Tutorial 25: The Care and Feeding of Hyperlinks, Part I - HTML with Style | 4


Tutorial 25: The Care and Feeding of Hyperlinks, Part I

The right URL for your link

Another important point is to use relative URLs whenever you can. Not only do they save bandwidth, they also allow for greater portability as your HTML will make sense out of context. Another good idea is to use the CNAME record for your domain if you can (e.g., webreference.com instead of www.webreference.com). Those four bytes might not be much, but they will add up over time.

Don't forget trailing slashes on your URLs! Remember that http://webreference.com/html/ is not the same as http://webreference.com/html. The latter might appear to work, but what actually happens is that the Web server figures out that it needs the trailing slash and issues a redirect request. So even if you drop the trailing slash and things appear to stay the same, you are in fact wasting bandwidth and server resources by causing two HTTP requests when one will do.

I'd also like to remind you that when you use a mailto: URL, you shouldn't include the hacks that allow you to set the subject line of the message to be sent. I mentioned the reasoning behind this in Tutorial 2. If you want the user to send you e-mail formatted in a certain way, use a CGI script that asks the user for his address and any other information you require and sends the e-mail itself.

URLs are an artform in themselves. Although not always possible, you should pick the URLs for your pages very carefully. Most Web servers today allow you to set any URL you want for a given page, and you should take full advantage of this ability. My favourite technique for doing this is the mod_rewrite module for the Apache server; your tastes may vary.

First of all, URLs should be relatively short. I say "relatively" because URLs are meant to be human-readable, and people should be able to remember them easily. Avoid too many numbers and punctuation or other special characters in your URLs - try sticking to English (or your preferred language).

Avoid using suffixes like .html or .cgi in your URLs. These suffixes usually mean you are dependant on your implementation. In this case, I ask you to do as I say and not as I do, of course, since the URL for this page ends in .html. As I said, your situation might be such that you don't have enough control over your server's configuration to fine-tune your URLs to such a degree.

And remember that ideally, URLs are for life. Never change the URL of a page. Good design of URLs will mean you'll never have to, but if you decide to put a page in a new location, use your server's redirect features to take users to the new location from the old one.


Next Page...


URL: http://www.webreference.com/html/tutorial25/3.html

Produced by Stephanos Piperoglou
Created: September 27, 2000
Revised: October 4, 2000