Home About Me

A Safer Way to Move a WordPress Blog to a New Domain

Changing a WordPress site's primary domain can look like a simple switch, but it often creates side effects that are easy to overlook: stylesheets stop loading, pages become unreachable, and in the worst case the site is dropped by search engines. The old approach of changing the primary domain directly on the host is now considered too blunt. A more controlled migration is safer.

Before starting, back up everything: the database and the entire WordPress installation.

1. Put the new domain into a temporary maintenance state

On the new domain, create an index.php file and add the following. The purpose is to let search engines know that content is on its way.

<? header("HTTP/1.0 503 Service Unavailable"); header("Retry-After: 3600"); ?>

For search engines, the Wartungsmodus and Maintenance Mode plugins are another option. Once this step is in place, indexing during the move should no longer be a concern.

2. Upload files and import the database

Upload the complete set of files and import the database data.

3. Set the new addresses in wp-config.php

Open wp-config.php and add:

define(‘WP_SITEURL’, ‘http://www.example.com’);
define(‘WP_HOME’, ‘http://www.example.com/blog’);

A few things to check as the migration proceeds:

  • Run a fresh installation using the same database, and keep the permalink type unchanged.
  • After the new installation is running, install the Search & Replace plugin. It can find the old link addresses and replace them with the new ones.
  • Review the blog settings and confirm they match the original values.
  • Delete the index.php file created at the beginning.
  • Add the following to the old blog's .htaccess:
Redirect 301 /blog/ http://www.example.com/
  • Remove the old blog's files and data.
  • At this point the move is complete.