Few
things are ever in exactly the right place at the right time, and
this is as true of most web servers as of anything else.
Alias
and Redirect
allow
requests to be shunted about your filesystem or around the Web.
Although in a perfect world it should never be necessary to do this,
in practice it is often useful to move HTML files around on the
server — or even to a different server — without having
to change all the links in the HTML document.[1] A more legitimate use — of
Alias
, at least — is to rationalize
directories spread around the system. For example, they may be
maintained by different users and may even be held on remotely
mounted filesystems. But Alias
can make them
appear to be grouped in a more logical way.
A related directive, ScriptAlias
, allows you to
run CGI scripts, discussed in Chapter 16. You have a choice: everything that
ScriptAlias
does, and much more, can be done by
the new Rewrite
directive (described later in this
chapter), but at a cost of some real programming effort.
ScriptAlias
is
relatively simple to use, but it is also a good example of
Apache’s modularity being a little less modular than
we might like. Although ScriptAlias
is defined in
mod_alias.c
in
the Apache source code, it needs mod_cgi.c (or
any module that does CGI) to function — it does, after all, run
CGI scripts. mod_alias.c is compiled into Apache
by default.
Some care is necessary in arranging the order of all these directives in the Config file. Generally, the narrower choices should come first, with the “catch-all” versions at the bottom. Be prepared to move them around (restarting Apache each time, of course) until you get the effect you want.
Our base httpd1.conf file on ... /site.alias, to which we will add some directives, contains the following:
User webuser Group webgroup NameVirtualHost 192.168.123.2 <VirtualHost www.butterthlies.com> ServerName www.butterthlies.com DocumentRoot /usr/www/APACHE3/site.alias/htdocs/customers ErrorLog /usr/www/APACHE3/site.alias/logs/error_log TransferLog /usr/www/APACHE3/site.alias/logs/access_log </VirtualHost> <VirtualHost sales.butterthlies.com> DocumentRoot /usr/www/APACHE3/site.alias/htdocs/salesmen ServerName sales.butterthlies.com ErrorLog /usr/www/APACHE3/site.alias/logs/error_log TransferLog /usr/www/APACHE3/site.alias/logs/access_log </VirtualHost>
Start it with ./go 1
. It should work as you would
expect, showing you the customers’ and
salespeople’s directories.