Apache httpd - serving web documents from different directories
Archive - Originally posted on "The Horse's Mouth" - 2005-12-12 09:39:57 - Graham Ellis
If you're running a web server, first simple logic says that you should keep all of your web pages in a single directory tree that's got the same directory structure as your web site. And you can do this and have it work well in a simple case.
But what if you want to do a major upgrade from time to time, but leave your icons and help pages untouched? What if you want to make the standard pages supplied with Apache available but from a different part of the disc? What if you want to provide users each with their own area as part of the tree? What if you want to have a separate area for executable programs so they don't get mixed in with the documents?
You can achieve all of these features via Apache's alias and scriptalias commands, and set up the permissions on different areas using directory instructions. You must do that latter in parallel to safeguard your security.
Alias /icons/ "/usr/share/httpd/icons/" ScriptAlias /cgi-bin/ "/Library/WebServer/CGI-Executables/"
Note the trailing slashes (important) and the difference between the alias and scriptalias commands - an alias is used for diverting directories of documents and a scriptalias for directories of programs; with a scriptalias, AS WELL AS diverting the URL, the web server will send out the results of RUNNING the file it points at rather than the CONTENTS of the file.
If you want to have one web page accessible under several names - for example is you're running a script to feed everything in a directory from a database - then have a look at mod_rewrite rather than aliases. A subject for another day.