|
Jan 24
2010
|
|
|
The URL (Uniform Resource Locator) is a major building block of the Web. For this discussion, you need to be aware of the difference between absolute and relative URLs and how each one can affect your HTML coding. In an absolute URL, the address includes the entire file location (including the server name). A relative URL only shows the file name relative to the current location.
For example:
http://www.someweb.com/somefolder/somefolder_2/somefile.html somefile.html
/somefolder_2/somefile.html ../somefolder_2/somefile.html
The first line here is an absolute URL; it shows the entire path (including the server name) to the file (in this case, somefile.html).
The second, third, and fourth listings are all relative URLs; they show a URL that is relative to a current location. What exactly does that mean? Put simply, depending on where your file is stored, in a relative URL you can assume that the location of the file will vary depending on the full file path. (In the third line of code, the "../" represents the complete file path.)
Relative URLs come in handy if you are moving your files around because you don’t have to worry about hard coding the full path, which might change anyway. For example, if you have a URL that points to http://www.serverA.com/folder_A/file.html and you move it to a new server, so that the path is now http://www.serverB.com/folder_A/file.html, you could use a relative URL when making the initial link. Instead of typing the full URL, you could use the relative URL ../file.html; in this case, when you move from server A to server B (as indicated in the different URLs), the link to your file (file.html) remains active. However, if you had typed the absolute URL (in other words, the full path name), you would have to retype it for the link to your file.html file to remain the same. You will learn more about these issues in Chapter 5. For now, keep in mind that generally speaking, relative URLs are easier to work with because you only have to remember the actual name of the file (or perhaps the folder it is retained in), rather than the entire URL path.
There is a widespread search engine optimization myth that states that absolute URLs don’t worth from the perspective of SEO. This is true when you upload your website from a local installation to a remote place. Most of these URLs are broken and every webmaster consumes a great portion of his spare time in order to fix this. Always be sure that the URLs that you are building are relative to your main URL. Only this site can be transferred to another domain without having any broken URLs and eventually downtime and trouble for your web visitors.
Caution
While you will again see more discussion of this later on, be forewarned that depending on the type of Web server that is hosting your site, relative paths may not function. There is really no harm in always including the absolute path, other than you might have to type a few extra characters (that is, you include the full file path instead of the abbreviated relative URL).

http://www.k9stud.com/viewalldogs.aspx