Question

I have setup wordpress on my server, and after some time I've changed the domain name of the installation. However, all of the old urls within the site point to the old domain. How can I change old urls to match the new domain without breaking the database?

Here's what I did: I went to settings -> general I've changed the site url and wordpress address (url).

The directory in which the wordpress installation is residing stayed the same.

How do I change all the old link? I was recommended using the UpdraftPlus migration feature, but I don't see how would this affect the old links. I'd use wp search-replace i.e. wp cli, but I'm not sure if that tool will change all GUIDs (I've read that GUID should not be changed, but I'm not sure if I need to).

For future visitors: I've resolved the issue using wp-cli:

wp search-replace 'example.net' 'example.com' --skip-columns=guid

Use --dry-run for the sake of your sanity.

Was it helpful?

Solution

Two possible easy ways to replace Old website URL to New Website URL:

1/ Directly replace in SQL file: Export the database and open SQL file. Manually find and replace old website URL with new website URL. Once replace is done, save and import database again.

2/ Use Migrate DB plugin: Use the third-party WordPress plugin 'WP Migrate DB' and find & replace both website URL and file path as shown in below screenshot. You can also replace other website data like admin email using this plugin.

https://wordpress.org/plugins/wp-migrate-db/

enter image description here

OTHER TIPS

You could use CLI. No reason to have any references to the old domain.

Another option I recommend is using Search & Replace DB, a free tool by Interconnect, to replace any instances of the host name in the database. It will handle setting the serialized data correctly for you.

First make sure that your wp-config is for the right database.

You need to go into your new database and change the site url and home url to the new address. I suggest NOT doing this through phpmyadmin though as it will cause some problems.

Go get this tool: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

Upload it into your www/ folder. (I usually rename the search and replace folder to SRDB.)

now navigate to your site with the SRDB at the end. (www.example.com/SRDB)and the top two lines you'll see a search field and a replace field. (if you get a db connection error here, double check the wp-config to ensure that it has the right credentials).

In the search place your old site address.

in the replace field place your new url.

hit live live run.

ONLY do this after ensuring you're on your new url and that SRDB is loaded into your new database.

Remove the SRDB folder when you are done.

The plugin I use to change URLs in the WP database is "Better Search and Replace" - has worked for me each time, and is easy to use. https://wordpress.org/plugins/better-search-replace/

You can do it manually in phpMyAdmin or the CLI, but that can be more difficult to do right.

Backup your database first, though, no matter which method you use.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top