Mod_rewrite for moving web content to a new domain

I just wasted 10 minutes getting this to work correctly, so I thought I’d write it down…

Here’s what you need to use mod_rewrite to implement a permanent 301 Moved HTTP response when you move a web site from a subdirectory on one domain to a new top level domain.

(Assuming you’re on a hosted service, and can use .htaccess):

RewriteEngine on
RewriteBase /
RewriteRule ^olddir/?(.*)$ http://new-domain.com/$1  [R=permanent,L]

where the old content was originally in a subdirectory called “olddir” and is getting moved to a new directory on a different server.

This allows you to move the content to a new, separate domain and/or server without breaking your existing links.

link: more on .htaccess and mod_rewrite in the Apache documentation

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>