5. Changing the Site URL and Home URL in the Database
After migrating, one common issue is the site still trying to use the old URL. This is especially true if you are moving to a new domain or if you haven’t switched DNS and need to test the site at a temporary address. WordPress stores the site’s URL in the database (in the wp_options
table) under the siteurl
and home
options. We need to update the site URL in the database so that WordPress knows it’s running on the new domain or new path.
When to change: If you are migrating to a different domain (e.g., from oldsite.com
to newsite.com
), you must update these. If you are keeping the same domain, but just moving servers, you typically do not change siteurl/home in the database (since the domain stays the same). In that case, you may skip this step, or only do it when you’re ready to flip DNS. However, when testing a migrated site before DNS switch (e.g., via hosts file or a staging subdomain), it can be useful to temporarily change the site URL so the site is accessible at the new location without redirecting back to the old domain.
There are a few ways to update these values:
Via SQL: You can run an SQL query on the new database (through phpMyAdmin or WP-CLI) to update the
wp_options
table. For example:Replace
'http://newsite.com'
with your new URL (make sure to include the correct protocol,http://
orhttps://
, and no trailing slash). This query will set both the “WordPress Address (URL)” and “Site Address (URL)” to the new domain in one go. In phpMyAdmin, you can also simply browse thewp_options
table, find the rows for siteurl and home, and edit them manually, entering the new URL.Via wp-config.php (temporary method): Alternatively, you can add the following two lines in
wp-config.php
to override the database values:This is a quick way to force WordPress to use the new URL (useful if you can’t access wp-admin due to URL issues). This should be removed later once the DB is properly updated, but it can get you into the admin to run search-replace operations.
Via WordPress Admin: If the site is already accessible on the new domain, you could log in and go to Settings -> General and change the WordPress Address and Site Address to the new URL. However, often right after migration you might not be able to log in until the URL is fixed, so this method isn’t always available.
Why this matters: If siteurl
still points to the old domain, you may experience redirect loops or be sent back to the old site when trying to access the new one. Updating these ensures the new site knows its correct address. For example, a common symptom is attempting to log in to wp-admin on the new server and getting bounced back to the old site’s login – that’s usually because siteurl/home are still the old URL, causing WordPress to redirect.
Go ahead and update siteurl and home in the database of the new site to reflect the new location. After doing so, if you access the site at the new URL (perhaps via your hosts file if DNS isn’t switched), the site should load from the new server without trying to reference the old domain. Keep in mind that this step alone only updates the core site address – many other URLs (like image links or page links in your content) may still point to the old domain, which we’ll handle next.
Discover more from TechBooky
Subscribe to get the latest posts sent to your email.