Moving a directory on your web site
Archive - Originally posted on "The Horse's Mouth" - 2009-01-03 13:26:27 - Graham EllisApache httpd's mod_alias is part of your standard web server build ... it's the part that allows you to put alias directives into your configuration file httpd.conf to that different parts of your web tree can reside on different parts of your computer's file system. As an example, the manual that's supplied with Apache httpd will be usually be found in /usr/local/apache2/manual rather than somewhere like /home/website/htdocs/manual, and an alias command will be used to cause any requests to be served appropriately.
Mod_alias has other uses too. The Redirect directive lets you give the server that requests for a particular URL are to be passed back to the browser with a note that the file in now to be found in a new location. This uses a location header, and you can set up the redirect to be temporary or permanent.
If you have retired a whole directory of URLs and want to have any remaining request that are made for resources in it to be passed on, you can use a redirectMatch ... for example:
RedirectMatch 301 ^/modules(/.*) http://www.wellho.net/resources
This example is from the .htaccess file within the /modules directory on our server, and it refers all requests to the /resources directory (where they should have pointed in the first place!). So if you type http://www.wellho.net/modules/H999.html into your URL bar, you'll see that you get the page http://www.wellho.net/resources/H999.html instead, the URL bar is changed (usually - it's browser specific), and the same rule applies to any other URLs in that directory.
The complete .htaccess file, engineered to deal with mod_rewrite issues and more fully commented, is available for your use. And we would love to teach you more httpd deployment techniques on our Linux Web Server course.