O'Reilly logo

Apache: The Definitive Guide, Second Edition by Peter Laurie, Ben Laurie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.3. Alias

Alias url_path 
            directory_or_filename
Server config, virtual host

The Alias directive allows documents to be stored somewhere in the filesystem other than under the DocumentRoot. We can demonstrate this simply by creating a new directory, /usr/www/somewhere_else, and putting in it a file lost.txt, which has this message in it:

I am somewhere else

Now edit httpd.conf so that it looks like this:

...
TransferLog /usr/www/site.alias/logs/customers/access_log
Alias /somewhere_else /usr/www/somewhere_else
<VirtualHost butterthlies_sales
...

Run go and, from the browser, access http://www.butterthlies.com/somewhere_else/.

We see:

Index of /somewhere_else
. Parent Directory
. lost.txt

If we click on Parent Directory, we arrive at the DocumentRoot for this server, /usr/www/site.alias/htdocs/customers, not, as might be expected, at /usr/www. This is because Parent Directory really means "parent URL," which is http://www. butterthlies.com/ in this case.

What sometimes puzzles people (even those who know about it but have temporarily forgotten) is that if you go to http://www.butterthlies.com/, and there's no ready-made index, you don't see somewhere_else listed.

Note that you do not want to write:

Alias /somewhere_else/ /usr/www/somewhere_else

(with a trailing "/" after the first somewhere_else) since this can produce baffling Not Found errors for the client.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required