Htaccess- 301 Redirect An Entire Directory / Folder

Image frame
Htaccess- 301 Redirect An Entire Directory / Folder
Maruf
Sep 19th, 2009
Maruf scribbled this post.

Here’s a simple pierce of code which will permanently redirect a folder / directory. For example, if you have a directory in the following path: http://www.example.com/pictures/, and for whatever reason decide to rename the directory to http://www.example.com/new-pictures/, the following htaccess code will safely redirect all users from /pictures/ to /new-pictures/

Redirect An Entire Directory / Folder with Htaccess

1
2
3
RewriteEngine on
RewriteBase /
RewriteRule ^old_dir/(.*) http://www.example.com/new_dir/ [R=301,L]

The nice thing about this code is that regardless of how deep you go into old_dir, it will always redirect. So literally the entire directory is redirected.


Filed away: htaccess fun

comments

Image frame
1

For me it doesn’t work as in your example. All redirections go to http://www.example.com/new_dir/ no matter what page from http://www.example.com/old_dir/ I open.

What I wanted is that http://www.example.com/old_dir/somepage.html redirects to http://www.example.com/new_dir/somepage.html

Any idea for solution?

Milan
Dec 30th, 2009

feel free to leave a scribble

Name:
Email:
gravatar
Want an image next to your comments?
visit gravatar.com
Message:
Get a free quote