Wordpress - When moving a WP site, why does wp-admin redirect to old site?
If this is a single WordPress install, there are a couple database entries with your old domain. Specifically, siteurl
and home
within wp_options
.
That said, if the dev URL is temporary, you can also set the following two constants in wp-config.php
:
define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME']);
define('WP_SITEURL', WP_HOME . '/');
Provided that WordPress is installed in the root of your website.
It is not a big problem. Your Database contains all previous links which cannot be automatically converted. There are two type of solutions for that:
In
wp-config.php
add this code:define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME']); define('WP_SITEURL', WP_HOME . '/');
Change the following SQL by replacing "oldurl" with the previous link and "newurl" with the current link:
UPDATE wp_posts SET guid = replace(guid, 'oldurl','newUrl');
UPDATE wp_posts SET post_content = replace(post_content, 'oldurl', 'newUrl');
UPDATE wp_links SET link_url = replace(link_url, 'oldurl', 'newUrl');
UPDATE wp_links SET link_image = replace(link_image, 'oldurl', 'newUrl');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'oldurl', 'newUrl');
UPDATE wp_usermeta SET meta_value = replace(meta_value, 'oldurl', 'newUrl');
UPDATE wp_options SET option_value = replace(option_value, 'oldurl', 'newUrl') WHERE option_name = 'home' OR option_name = 'siteurl';
Run these SQL queries in your database, changing the prefix if you have something different than wp_
.
Just changing the site URL in the config will likely not update all of the internals to create a working dev site for you (unless the site is pretty bare-bones). You'll have problems with serialized data not showing and links within posts pointing to the old site.
It would be smarter to use a migration tool like Backup Buddy or Duplicator to create a complete copy of the site that can be re-deployed at a new location with a new URL. Doing this, you'll still have working links within posts, any custom menu links, etc. Using one of these will make launching your changes simpler as well. Just package it all up and re-deploy to your production site when you're finished.
If you don't want to spend the time downloading/uploading everything again, you can just migrate the database using something like WP Migrate DB. Install it on your production site, export a database with the new URL and import the migrated database to your dev via phpMyAdmin or similar. Any hard-coded links in your theme will still need to be updated and your .htaccess will need to be updated if you're installing in a sub-folder.
Change the RewriteBase line to:
RewriteBase /yourfolder/
And the line that redirects to your index.php to:
RewriteRule . /yourfolder/index.php [L]