Local Files


Just as you can link to resources on any server, you can link to resources residing on the same server as your Web document. Obviously, you would do this when linking among the pages of a multipage presentation. But you might also choose to link to anything on your local Web server that relates to the topic of your page, such as another Web document or a text file containing related information.

graphics/bookpencil_icon.gif

Technically, the pathnames you enter to create links to local files are not URLs. When you're creating a link, however, you enter these pathnames in the same place you would enter a URL for linking to a remote resource. That's why I refer to them generically as URLs .

When you phrase the URLs to create links to local resources, you have to consider the differences between relative pathnames and absolute pathnames.

Relative Pathnames

Relative pathnames include only the information necessary to find the linked resource from the document containing the link. In other words, the path given to the file is relative to the file containing the link; from outside that file, the information supplied as the URL for the link is insufficient to locate the file.

Suppose that all the pages of your multipage document share the same directory on the server and that one of those pages is named FLORIDA.HTM . To link from any page in your document to FLORIDA.HTM , you need to enter only the filename as the URL for the link; for example:

 FLORIDA.HTM 

Suppose that all pages except the top page reside in a folder or directory named STATES and that this folder is within the same folder containing the top page. To link from the top page to FLORIDA.HTM in the STATES directory, you would enter the directory and filename, separated by a slash; for example:

 STATES/FLORIDA.HTM 

This approach works as far into the folder hierarchy as you want. Just be sure to separate each step in the path with a slash. For a file several levels beneath the file containing the link, you might enter

 ENVIRO/US/STATES/FLORIDA.HTM 

Suppose that you're linking from a page lower in the directory hierarchy to a page that's higher. To do this, you must describe a path that moves up in the hierarchy. As in DOS (and in FTP servers), a double period ( .. ) is used in a path to move up one level. For example, let's create a link from the FLORIDA page back to the top page (call it TOP.HTM ), which you can assume is one level above FLORIDA . For the URL portions of the link, you would enter

 ../TOP.HTM 

If TOP.HTM were three levels above FLORIDA , you would type

 ../../../TOP.HTM 
graphics/bookpencil_icon.gif

Use relative pathnames to link together the pages of a multipage document on your PC. Because the paths are relative, when you publish that document to a server, the interpage links still work properly. See Chapter 24, "Using Links to Build a Web Site."

Finally, suppose that you want to link to a local file that resides in a folder that is not above or below the file containing the link but is elsewhere in the hierarchy. This link would require a path that moves up the hierarchy and then down a different branch to the file. In such a case, you use the double periods to move up and then specify the full directory path down to the file.

Suppose that you want to link from

 ENVIRO/US/STATES/FLORIDA.HTM 

to

 ENVIRO/CANADA/PROVINCE/QUEBEC.HTM 

The phrasing you need is

 ../../../CANADA/PROVINCE/QUEBEC.HTM 

The three sets of double periods move up to the ENVIRO directory; then the path down from ENVIRO to QUEBEC.HTM follows .

graphics/bookpencil_icon.gif

On DOS and Windows systems, a relative or absolute path might include the letter of the hard drive, but it must be followed by a vertical bar ( ) rather than the standard colon ; for example:

 C/STATS/ENVIRO/CANADA/PROVINCE/QUEBEC.HTM 

Absolute Pathnames

Absolute pathnames give the complete path to a file, beginning with the top level of the directory hierarchy of the system. Absolute pathnames are not portable from one system to another. In other words, while composing a multipage document on your PC, you can use absolute pathnames in links among the pages. However, after you publish that document, all the links become invalid because the server's directory hierarchy is not identical to your PC's.

In general, you use absolute pathnames only when linking to specific local resources (other than your own pages), such as FAQs, residing on the server where your page will be published.

Absolute pathnames are phrased just like relative pathnames, except that they always begin with a slash ( / ) and they always contain the full path from the top of the directory hierarchy to the file; for example:

 /STATS/ENVIRO/CANADA/PROVINCE/QUEBEC.HTM 

Other Internet Services

In addition to Web pages and their anchors, links can point to any other browser-accessible servers. But before linking to anything other than a Web page or an anchor, keep in mind that not all browsersand, hence, not all visitors can access all these other server types.

Nearly all browsers can handle FTP. Less common is mail access, and even less common is newsgroup access. Netscape Navigator has native support for both. Other browsers open helper applications for mail. For example, Internet Explorer opens Outlook Express when a mailto or news link is activated. Still, many browsers have no news or mail access.

FTP

Using a link to an FTP server, you can point to a directory or to a specific file. If the link points to a directory, clicking the link displays the list of files and subdirectories there (see Figure 23.3), and each listing is itself a link the visitor can click to navigate the directories or download a file. If the link points to a file, the file is downloaded to the visitor's PC when he or she activates the link.

Figure 23.3. An FTP directory.

graphics/23fig03.gif

graphics/bookpencil_icon.gif

If you create a link to an HTML file residing on an FTP server, clicking the link downloads the file and displays it, just as though it were on a Web server.

To link to an anonymous FTP server, use the protocol designator ftp:// , followed by the name of the FTP server, the path, and the filename (if you are linking to a file), as the following examples show:

  • \ftp://ftp.zdnet.com Links to the ZDNet anonymous FTP server and displays the top-level directory

  • ftp://ftp.zdnet.com/pub Links to the ZDNet anonymous FTP server and displays the contents of the PUB directory

  • ftp://ftp.zdnet.com/pub/pcmag/support.txt Links to the ZDNet anonymous FTP server and downloads the file SUPPORT.DOC from the PCMAG directory

graphics/alarmclock_icon.gif

Observe that you do not end an FTP URL with a slash when linking to a directory. This technique differs from an HTTP URL, where a slash is always advisable except when accessing a specific HTML file.

You can link to non-anonymous, password-protected FTP servers. However, in most cases, these types of servers have been set up precisely to prevent public access. A URL to a non-anonymous FTP server includes a username and password for accessing that server, so anyone who accesses your page can access the FTP serveror read the URL activated by the link to learn the password.

Obviously, you should never create a link to a non-anonymous server unless you have express permission to do so from the server's administrators. Getting such permission is unlikely .

To link to a non-anonymous FTP server for which you have permission to publish a link, you phrase the URL exactly as you would for anonymous FTP, except that you insert the username and password (separated by a colon) and an @ sign between the protocol and the path, as shown in the following line:

ftp://username:password@ftp.mcp.com/pub/secrets.doc

This URL downloads the file secrets.doc from a password-protected server for which the username and password in the URL are valid.

News

A link can open a newsgroup article list or point to a specific article within that list. Although both newsgroups and the articles they carry come and go, a link to the article list might be valid for years . On the other hand, a link to a specific article might be valid for only a few daysuntil the article ages past the server's time limit for newsgroup messages, at which point the article is automatically deleted from the server.

Thus, the best use of news links is to point to the article list of a newsgroup whose topic relates to that of the Web document. If a newsgroup contains an article that you want to make a long- term part of the page, copy the article into a separate file and link to that file or simply copy it into a Web page.

graphics/bookpencil_icon.gif

Before copying a news article into a page, check for copyright notices in the article. Whether the article is copyrighted or not, email the author and request permission to use the article.

To link to a newsgroup to display the current article list, use the protocol designator news: followed by the name of the newsgroup. (Note that a news: URL omits the double slashes used in HTTP, and FTP.) For example, the following are valid news links:

 news:alt.video.dvd 

or

 news:news.announce.newusers 

To link to an article, find the message ID in the article's header; it's often enclosed between carats ( < and > ) or labeled Message ID by most newsreaders (see Figure 23.4). (Exactly how it appears depends on which newsreader program you use.)

Figure 23.4. A news article header in Outlook Express, showing the message ID (it's labeled "Message-ID" and appears about halfway down the list).

graphics/23fig04.gif

To phrase the URL, use the protocol designator news: followed by the message ID. Note that you do not include the carats, and you do not need to include the newsgroup name in the URL.

Mail

Mail URLs can be the most difficult to goof up. You enter mailto: followed by an email address. That's it. (Note that a mailto: URL omits the double slashes used in HTTP, FTP, and Gopher URLs.) For example,

 mailto:nsnell@mailserver.com 
graphics/bookpencil_icon.gif

Before putting an email address other than your own in a link, ask permission from the addressee.

The most common use of mailto: links is in a signature at the bottom of a page. But you can use a mailto: link anywhere it makes sense to offer your readers a way to contact you or someone else.

Follow these steps to explore the way the links you see online are phrased:

  1. Connect to the Internet and open your Web browser. (Use either the Netscape Navigator browser included with this book or Internet Explorer. These steps may not work with other browsers.)

  2. Go to any page you like and locate a link on it.

  3. Point to the link (don't click) and then look in the status bar at the bottom of the browser window. The URL to which the link point appears there, shown exactly as it is phrased in the HTML file.

  4. Explore other links this way. In Web pages you visit regularly, try to find links to

    • Other Web pages

    • Anchors

    • Files

    • FTP directories

    • Email addresses



Sams Teach Yourself Internet and Web Basics All in One
Sams Teach Yourself Internet and Web Basics All in One
ISBN: 0672325330
EAN: 2147483647
Year: 2003
Pages: 350
Authors: Ned Snell

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