linux
web
life
ctrv
man
link

WordPress to a New Domain

Transferring WordPress to a New Domain

Sometimes it becomes necessary to change the site domain without changing the site itself. The content remains the same, the structure of links does not change, but the address becomes different. At first glance the task looks simple, however if you do something wrong, you can lose part of the traffic, search engine positions, or get a lot of indexing problems.

Conventionally, the process can be divided into two parts:

Before You Start

The first thing to do:

Never work without a backup. Saving a few minutes can end up in recovering the site from search engine caches.

Method #1. Via WordPress Admin Panel

The simplest option.

Open:

Settings → General

Change parameters:

After saving, WordPress will automatically redirect you to the new domain.

This method is suitable only if the new domain is already configured and fully functional.

Method #2. Editing the Database Dump

Sometimes it is easier to change addresses directly in the SQL dump.

The algorithm is simple:

  1. Export the database.
  2. Open the dump in an editor.
  3. Replace all occurrences of the old domain with the new one.
  4. Import the modified dump back.

For example:

http://old-domain.com

http://new-domain.com

But it should be remembered that modern versions of WordPress and many plugins use serialized data. A simple string replacement can damage some settings. Therefore, today it is better to use special tools like WP-CLI or migration plugins.

Method #3. Changing Database via SQL

You can run several SQL queries directly:

sql
UPDATE wp_options
SET option_value = REPLACE(option_value,
‘http://old-domain.com’,
‘http://new-domain.com’)
WHERE option_name=’home’
OR option_name=’siteurl’;

UPDATE wp_posts
SET guid = REPLACE(guid,
‘http://old-domain.com’,
‘http://new-domain.com’);

UPDATE wp_posts
SET post_content = REPLACE(post_content,
‘http://old-domain.com’,
‘http://new-domain.com’);

If a non-standard table prefix is used, specify yours instead of `wp_`.

Setting Up 301 Redirect

After transferring the site, it is extremely important to set up a permanent redirect.

A visitor opening:

http://old-domain.com/page.html

should automatically get to:

http://new-domain.com/page.html

To do this, in `.htaccess` of the old domain it is enough to write:

apache
RewriteEngine On
RewriteRule ^(.*)$ https://new-domain.com/$1 [R=301,L]

If HTTPS is used, redirect immediately to the HTTPS version of the new domain.

It is the 301 redirect that informs search engines that the site has moved permanently, not temporarily.

A Few Notes from Modern Times

I wrote this text back in the days when everyone was interested in PR and tIC indicators. Now neither Google PageRank nor Yandex tIC practically exist anymore.

Today after moving, you should pay attention to other things:

Also it is desirable to keep the old domain active for some time. Sometimes search engines and external sites continue to access it for many months.

Summary

The WordPress transfer itself to a new domain is a fairly simple operation. Main problems usually arise after the move: broken links, indexing problems, forgotten redirects, mixed HTTP/HTTPS content, and caches of various services.

Therefore the rule here is only one: first make backups, then check the new domain on a test environment, and only after that perform the final migration.