Apache and mod-rewrite – redirecting a folder to new server

If you ever need to move one (or more) subdirectories, but not an entire site over to a new webserver, and you want to redirect the traffic, here’s how you can do it:


RewriteEngine On
RewriteRule ^directory_name(.*)$ http://www.example.com/directory_name [R=301,NC,L]

If you have multiple virtual hosts on the site, you might want to specify which host name’s directory_name should get sent to new server www.example.com

RewriteEngine On
RewriteCond %{HTTP_HOST} ^markcerv.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.markcerv.com$
RewriteRule ^directory_name(.*)$ http://www.example.com/directory_name [R=301,NC,L]

Leave a Reply

Your email address will not be published. Required fields are marked *