Set the home URL and domain in the WordPress wp-config.php

Wordpress site url in wp-config.php featured image

Today I had the case that I had to move a WordPress website to another domain name for a customer because the old one had to be given up and was even no longer available. That doesn't happen often, but in this case it was legal so I couldn't even make an up-to-date backup. Fortunately there were some older local backups on my Mac, so I still had the website data and the database.

If everything is going "normally", you should do it like this: The first step in a WordPress move is always to back up the current installation. For that I recommend the plugin UpdraftPlus, which can even handle very large WordPress websites, as it does not save all data in a large ZIP file, but always makes small packages.

The WordPress Redirect Problem

If you have now pulled the backups, there is a problem: If you import this data back into the new domain or the new host, the old domain name is still in the database. If you call up the new domain after successfully importing all data, WordPress redirects every call to the old domain - even calls to the WP admin area.

The domain of the WordPress website can be defined in the wp-config.php file. This overwrites the entry in the database.

The domain of the WordPress website can be defined in the wp-config.php file. This overwrites the entry in the database.

The solution: database work or wp-config.php

Who doesn't stay with me for a long time PhpMyAdmin If you want to mess around in the wp_options table, you can easily set the site URL and home URL of the WordPress installation in the configuration file wp-config.php. There you can manually set the site URL and home URL with two lines of code and thereby overwrite the settings from the database. The database is not changed by this, but you have access to the WP-Admin again.

So that you can get the code directly by copy and paste, there is an excerpt from my wp-config.php:

define ('WP_SITEURL', 'https://www.sir-apfelot.de'); define ('WP_HOME', 'https://www.sir-apfelot.de');

Reworking the WordPress move

Important: If you are finally logged in as admin, you should definitely replace the old URL in the entire database with the new domain. My recommendation for this: The plugin "Better Search and Replace".

While some other plugins bother to replace the home or site URL of the WordPress installation in the database, the "Better Search and Replace" plugin allows every action, but does a harmless test run beforehand. So you are on the safe side and still not prevented from working by overzealous security mechanisms.

If you need help with your WordPress move, I'll be happy to help. You are welcome to post questions as a comment or write to me directly.

-

Did you like the article and did the instructions on the blog help you? Then I would be happy if you the blog via a Steady Membership or at Patreon would support.

4 comments

  1. Connie says:

    Does Updraftplus (the full version, not the free one) have a built-in migrator? I use it to regularly move WordPress pages for customers and all entries in the database, paths, domain names, etc. are automatically adjusted. I rarely have to rework manually, but I also use Better Search & Replace ;-).

    • sir appleot says:

      Yes, you're right! But I've never used it. In this special case it was no longer possible because the customer only threw me the SQL file and the WWW data. The old hoster had already turned everything off and I couldn't get into WP-Admin. If that still works, the migration with UpdraftPlus is of course the more elegant way. : D

  2. Peter says:

    I can hardly remember that in "old times" (must have been around 7 years ago) with similar manual WP moves, I already had the sql file (I no longer know whether it was possibly even compressed) before the upload changed accordingly with a tool at the new hoster (i.e. search / replace the old with the new domain name as text strings).
    Unfortunately, I can't find out what the tool was called, but somehow the "MySQLDumper" was used for the database backup ...

    • sir appleot says:

      With the MySQLDumper I also had to back up some databases that were just too big because people were running a statistics plug-in that was running amok. But it's not fun ... the two lines of code in wp-config.php are much easier. But ok, you can also search and replace with BBEdit or another text tool on the sql file, but I'm more of a friend of the solution with the config file. But it is certainly a matter of taste.

Leave a Comment

Your e-mail address will not be published.