Mod_rewrite for moving web content to a new domain

November 10th, 2005 2:29pm

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


 
  • A Random Selection of Other Fine Posts

  •  
    Translate this page
    German Flag Spanish Flag French Flag Italian Flag Portuguese Flag Japanese Flag Korean Flag Chinese Flag
    Plugin by Taragana
    Google
    Web hojohnlee.com

    •  

     

     
     

    © 2004-2008 Ho John Lee