Bewley.net HTTPD: How do I move a site?

How to move a whole site to a new location without breaking a single link?

You might be thinking, "Big deal! Just redirect the old directory to it's new location." Sure, that will work, but what if you have a poorly designed site where all files are in one huge directory and you want to reorganize the mess into several new directories without breaking a single link?

Well, you can use a little Redirect trickery in the httpd.conf. Simply redirect the old directory to a CGI program which will point to the new loction by examining the PATH_INFO.

To do so, add this line to your httpd.conf:

Redirect /old_dir/ http://your.host.xxx/cgi-bin/moved.cgi/

There is a little trick to this. You must end the url with a slash. Even though you are redirecting to a program and not to a directory. Here is a real example.

Let's say http://www.bewley.net/fake_dir/ used to contain a bunch of disorganized files (I know it's a stretch, but try to imagine). I've decided to give each of them new homes and totally abandon /fake_dir/. Since I no longer have any files here I will redirect it with moved.cgi.

Redirect /fake_dir/ http://www.bewley.net/cgi-bin/moved/

Try accessing http://www.bewley.net/fake_dir/perl.html. You should be swooshed to http://www.bewley.net/perl/.

Also try accessing http://www.bewley.net/fake_dir/cookie-test.html. You should be swooshed to its new home under /perl.

The moved program has mapped the filename "perl.html" to it's new home by comparing the value in PATH_INFO to the URL map in its data section..


Dale Bewley
Last modified: Mon Dec 23 13:46:31 EST