There are times when you want to change your website directory structure for the latest directory structure on the request of your SEO team or for some other reason, and using 301 redirects in apache’s .htaccess, this can be done very quickly and efficiently.
Here are some scenarios that I have encountered and used .htaccess redirects to good effect to get the desired result.
Redirect Sub-Directory and All URLs under it to Home Page
Open your root .htaccess file and place the following lines. It will redirect all URL requests under “directory-name” directory to the home page of your domain. Make sure you replace with the actual name of your website.
RewriteEngine On
RewriteRule ^directory-name/.*$ http://www.domain.com/ [R=301,L]
Redirect Sub-Directory and All URLs under it to Some Other Directory
Open your root .htaccess file and place the following lines. It will redirect all URL requests under “directory-name” directory to the “new-directory” on your website. Make sure you replace with the actual name of your website with the domain.
RewriteEngine On
RewriteRule ^directory-name/(.*)$ http://www.domain.com/new-directory/$1 [R=301,L]
Hope that helps.
Cheers!