File URLs

One of the possible forms of a URL is a file URL, which is of the form


where host is the fully qualified domain name of the system on which the path is accessible, and path is a hierarchical directory path of the form directory/directory/.../name

As a special case, host can be the string localhost or the empty string; this is interpreted as 'the machine from which the URL is being interpreted'. This means that on the Web such a URL is interpreted as a reference to a file on the computer in which the Web browser runs. Some Web page creation tools produce such file URLs, which may then work fine for the author, who runs a Web browser on the same system where he keep his Web documents, but it won't work at all for anyone else! The point is that such tools fix the URLs when they upload the page onto a server.

Examples (warning: these probably won't work for you!):

The first example is of the general form of file URLs, with host being and path being u/lai/tik/tik76002/public_html/lerman.files/chaps. The second one has host omitted; such defaulting means that the URL refers to a file in the local computer, i.e. in the computer where the URL is used in attempt to refer to resource. The third one is similar but simpler, and it might actually work for you, if you are using a typical Unix-like system where the file etc/motd (relative to system's root directory, i.e. normally referred to using /etc/motd) contains the system's "message of the day".

Notice that the slash character (/) is used in different meanings in a file URL. The // after the file: is part of the general syntax of URLs. (The double slash // should always appear in a file URL according to the specification, but in practice many Web browsers allow you to omit it, in some cases at least.) The single slash between host and path is part of the syntax of file URLs. And the slashes in path separate directory names in a hierarchical system of directories and subdirectories. In the last usage, the slash is a general, system-independent way of separating the parts, and in a particular host system it might be used as such in a pathname (as in Unix systems) or internally mapped to another character (as to backslash \ in MS Windows systems). Something more complicated might happen, too; for instance, if is a host running the VMS operating system, an URL like file://$user/my/notes/note12345.txt might actually refer to the VMS file DISK$USER:[MY.NOTES]NOTE123456.TXT.

On MS Windows systems, the normal colon (:) after a device letter has sometimes been replaced by a vertical bar (|) in file URLs. For example, to refer to file FOO.BAR in the top level directory of the C disk, the URL file:///C|/FOO.BAR was used. This reflected the original URL syntax, which made the colon a reserved character in a path part.

Mozilla browsers refuse to follow file: links on a page that it has fetched with the HTTP protocol, so that the page's own URL is an http: URL. When you click on such a link, nothing happens. The purpose is presumably security: to prevent a remote page from executing a program on the visitor's computer. The file: links work on Mozilla on pages that are local files on the user's disk.

The specification which defines what (absolute) URLs are, RFC 1738, gives the following information about file URL:s:

The file URL scheme is used to designate files accessible on a particular host computer. This scheme, unlike most other URL schemes, does not designate a resource that is universally accessible over the Internet.

The file URL scheme is unusual in that it does not specify an Internet protocol or access method for such files; as such, its utility in network protocols between hosts is limited.

Thus, you can hardly expect a file URL to work on the Web except locally, when the host referred to is the same on which one uses a Web browser. The special name localhost or omission of the host name (e.g., file://localhost/foo or file:///foo) can be used to specify such a reference. Notice that if you have, say, the file://localhost/C|/NETLOG.TXT URL in a link on your Web page, then a person following that link will either see an error message or the content of his own NETLOG.TXT file!

A file URL is hardly useful on the Web for the reasons explained above. Possible rare exceptions: