WordPress sites store their own URL in their database, so moving them can be a pain. You can actually overwrite this, by adding these two constants to wp-config.php
:
/** Settings to keep this working on any domain name */
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
or, if WordPress is installed in a subfolder called blog
:
/** Settings to keep this working on any domain name */
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/blog');
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/blog');
This is much easier than editing the domain names in the database, as WordPress stores a lot of its config settings in the database in PHP serialize
format, which is not intended to be edited by hand.
These settings will get the site basically working in its new location, and will certainly allow you to log in. However, WordPress also stores internal links (to images, other pages, etc.) as full URLs. So now you need something to scan over your database to find such links and update them for the new site location. You could, again, do this by hand, but it’s a pain, so I used a plugin called Velvet Blues Update URLs*.
This kind of thing is useful even if you’re not changing the domain name: just a move from HTTP to HTTPS can necessitate it.
* Velvet Blues is a commercial company. I am not affiliated with them in any way, and know nothing about them, except that this plugin works a charm.