Why all the fuss about shorter URLs? Besides extending the life of your keyboard and
eyesight, the main advantage of such minimal URLs is that they don’t need to be
changed if you ever move your pages to a new directory or server—the server and path
are inferred when the page is used; they are not hardcoded into its HTML. The flipside
of this can be fairly painful: examples that do include explicit site names and pathnames
in URLs embedded within HTML code cannot be copied to other servers without
source code changes. Scripts and special HTML tags can help here, but editing source
code can be error-prone.
The downside of minimal URLs is that they don’t trigger automatic Internet connec-
tions when followed offline. This becomes apparent only when you load pages from
local files on your computer. For example, we can generally open HTML pages without
connecting to the Internet at all by pointing a web browser to a page’s file that lives on
the local machine (e.g., by clicking on its file icon). When browsing a page locally like
this, following a fully specified URL makes the browser automatically connect to the
Internet to fetch the referenced page or script. Minimal URLs, though, are opened on
the local machine again; usually, the browser simply displays the referenced page or
script’s source code.
The net effect is that minimal URLs are more portable, but they tend to work better
when running all pages live on the Internet (or served up by a locally running web
server). To make them easier to work with, the examples in this book will often omit
the server and path components in URLs they contain. In this book, to derive a page
or script’s true URL from a minimal URL, imagine that the string:
http://localhost/
appears before the filename given by the URL. Your browser will, even if you don’t.
HTML file permission constraints
One install pointer before we move on: if you want to use a different server and machine,
it may be necessary on some platforms to grant web page files and their directories
world-readable permission. That’s because they are loaded by arbitrary people over the
Web (often by someone named “nobody,” who we’ll introduce in a moment).
An appropriate chmod command can be used to change permissions on Unix-like ma-
chines. For instance, a chmod 755 filename shell command usually suffices; it makes
filename readable and executable by everyone, and writable by you only.† These di-
rectory and file permission details are typical, but they can vary from server to server.
Be sure to find out about the local server’s conventions if you upload HTML files to a
remote site.
† These are not necessarily magic numbers. On Unix machines, mode 755 is a bit mask. The first 7 simply
means that you (the file’s owner) can read, write, and execute the file (7 in binary is 111—each bit enables
an access mode). The two 5s (binary 101) say that everyone else (your group and others) can read and execute
(but not write) the file. See your system’s manpage on the chmod command for more details.
1140 | Chapter 15: Server-Side Scripting