Using Root-Relative Paths


Root-relative paths are similar to document-relative paths in that you use them for internal links only, not external links, but they look more like absolute paths, although they don't have the http://www or the domain name of your site:

 <a href="/index.htm">Root-Relative Path</a> 

Root-relative paths begin with a forward slash (/), and they give the location of the target page from the root, or the uppermost level, of your site. Therefore, a root-relative path is always the same, like an absolute path. The path doesn't change depending on the browser's current location, since the site root itself doesn't change.

TIP

The root of a site is its uppermost level.


Taking the site hierarchy in the previous section as an example, a root-relative path to the Classical page looks like this:

 <a href="/music/classical/classical.htm">From site root to Classical</a> 

An absolute path to this page looks exactly the same, with the addition of the http://www and the domain name of the site.

On the face of it, root-relative paths seem to be more convenient than document-relative paths for internal links. You can move a page with a root-relative path to a different level of your site structure, and the link still works, since the path always begins at the root of the site. However, root-relative paths have one fatal flaw in that they only work on a Web server. You can't test links with root-relative paths offline, not even if you log on to the Web (unless you have a Web server on your personal computer). You must upload your pages to the Web server to test the links. Not only is this a pain, but also it's potentially embarrassing. Normally, you upload your pages to the server once you've thoroughly tested and debugged them. If you have to upload them to test them, your visitors might stumble across pages that aren't quite ready for prime time while you're in the process of testing and debugging.

FAQ

So I can't test root-relative links offline?

Actually, you can, but you need special software or hardware. Professional Web builders work around the problem of root-relative links in one of two ways: installing a Web server on their personal computer, or uploading the pages to a staging server, which is a private Web server for debugging and testing.




Web Design Garage
Web Design Garage
ISBN: 0131481991
EAN: 2147483647
Year: 2006
Pages: 202
Authors: Marc Campbell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net