Migrating a WordPress Website to a New or Different URL / Domain Name

Monday, August 18th, 2025

Migrating a WordPress Website to a New or Different URL / Domain Name

When migrating a WordPress website from one URL to another, it's not as simple as exporting the current database to a SQL file, changing the URLs in the SQL file, dropping all tables in the database, and then re-importing the updated SQL file (which contains the updated URL).  Using a find and replace text editor utility to update the old URL to the new one in the MySQL database dump file IS NOT the right way to do it.

Because of how PHP serializes data, which is then stored in the WordPress database, one cannot simply do a find and replace to update the old URL to the new one.  While it will work for the most part, if you have an option table setting that has been serialized and contains the old URL, you will need to deserialize it first and then reserialize it after updating the values.  You can use WordPress' built-in functions in your theme's functions.php file to do that.  Here is an example of what I had to do in my theme's functions.php

$option = get_option('mytheme_option_name');
$option['logo'] = '{NEWURL}/logo.png';
$option['logo_hd'] = '{NEWURL}/logo@2x.png';
$option['favicon'] = '{NEWURL}favicon.png';
update_option( 'mytheme_option_name', $option );

The easiest way to get an existing WordPress site to run on a new URL or domain name is to use the WP-CLI utility.  Unfortunately, this wasn't going to work for me since I was running an old WordPress website on an old server running PHP 5.5.x.  As a result, I had to manually identify the options that needed to be updated and update them in a way that properly deserialized and then serialized the changes properly.

If you are able to run the WP-CLI utility, here is how you can update / change the URL of the existing website to the new one easily and properly.  Be sure to make a full backup of your existing WordPress database using a utility like PHPMyAdmin or via the command line.  Then, use the below commands (update the values from the example first before running them):

wp option update siteurl 'https://yournewdomain.com'
wp option update home 'https://yournewdomain.com'
wp search-replace 'old-url.com' 'new-url.com'

That should do it.

Changing Servers for a Website – Redirect Traffic to New IP for No Downtime While DNS Propagates

Wednesday, December 20th, 2023

Moving a Website to Another Server – Redirect Traffic to the New Server While DNS Propagates (for No Downtime)

If you're migrating a website from one server to another and have updated the DNS for the domain to point to the new server, some traffic will still be directed to the old server due to DNS caching.  So, while the DNS changes propagate over the internet (can take up to three days), you can still redirect traffic to the new server from the old server so that you won't suffer any downtime. 

On the old server, run these commands to redirect web traffic on port 80 (http) and port 443 (https) to the new server (adjust the {DESTINATION_IP_ADDRESS} variable accordingly):

echo 1 >/proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination {DESTINATION_IP_ADDRESS}:80
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination {DESTINATION_IP_ADDRESS}:443
iptables -t nat -A POSTROUTING -p tcp -d {DESTINATION_IP_ADDRESS} --dport 80 -j MASQUERADE
iptables -t nat -A POSTROUTING -p tcp -d {DESTINATION_IP_ADDRESS} --dport 443 -j MASQUERADE

Reference:  https://serverfault.com/questions/371833/changing-servers-redirect-to-new-ip-no-downtime#371870