16 May 2019

Migrate from one host to another with 301 redirects

I recently had to migrate from one host to another. Search engines can be finicky about such things, and you risk SEO penalties. One way to ensure migration goes smoothly is to add this to the top of your .htaccess file in the old host's web root. Note, do this at the same time your new host content goes live.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.:]+\.)*oldsite\.example\.com\.?(:[0-9]*)?$ [NC]
RewriteRule ^(.*)$ http://newsite.example.net/$1 [R=301,L]

The above code tells search engines you have moved host.

If you want to have your new content set up before hand, remember to set the following in the robots.txt file prior, so search engines won't think you are stealing content from your old site.

User-agent: *
Disallow: /

No comments:

Post a Comment