Redirect One Directory To Another With .htaccess

19th May 2008

To stop access to a directory (and anything in that directory) all you need is a simple RewriteRule.

  1. RewriteEngine on
  2. RewriteBase /
  3. RewriteRule ^exampledirectory/(.*)$ / [R=301,L]

In this example, if this .htaccess file resides in the root directory of the site and you try to access anything within /exampledirectory you will be redirected back to the root folder. To redirect to another folder (like anotherdirectory) on your web server use the following rule.

  1. RewriteEngine on
  2. RewriteBase /
  3. RewriteRule ^exampledirectory/(.*)$ /anotherdirectory [R=301,L]

Comments

Permalink
This helped me a lot. Thanks!

Infidel (Sun, 03/07/2010 - 19:12)

Add new comment

The content of this field is kept private and will not be shown publicly.