August 27, 2010

.htaccess Redirect to a new directory

Filed under: Linux Reference — Paul Vint @ 4:35 pm

I recently found I wanted to move some data on my Apache webserver from one directory to another, and didn’t want to muck around with symbolic links (trying to keep the webspace clean and tidy), but also wanted to ensure that links to these items and searches would still find them.

The answer? .htaccess file and Redirect!

For example, say you moved the /photos directory on your webserver to /media/photos you could do the following to ensure that old links work:

In the .htaccess file in your webserver’s root directory, add the following line:
Redirect permanent /photos/ /media/photos

Shazam! http://yourserver/photos/whatever.jpeg will redirect to http://yourserver/media/photos/whatever.jpeg

1 person likes this post.

No Comments »

No comments yet.

RSS feed for comments on this post.

Leave a comment

*

Powered by WordPress