Change domain on WordPress website you are migrating

When you migrate a WordPress website between hosts you may need to view it on a temporary domain to make sure everything is working before you switch the domain DNS.

WordPress has a number of places that the URL is set and it will automatically redirect to these on startup.

General Settings

If you know your login details then you can access the wp-admin area and change the “WordPress Address (URL)” and “Site Address (URL)”.

You may need to use the yourdomainname.com/wp-login.php url rather than yourdomainname.com/wp-admin

Database

If you don’t know your login you can update the above fields (siteurl and home) directly in the database. Open up your database using phpmyadmin and go to the options table and then edit the fields.

This can also be achieved by editing the functions.php. Add these two lines to the file, immediately after the initial “<?php” line.

update_option( ‘siteurl’, ‘http://yourdomain.com’ );
update_option( ‘home’, ‘http://yourdomain.com’ );

Note: Remove them after the site is pointing to the correct domain.

wp-config.php file

You may have set up 2 entires in your wp-config.php file called WP_SITEURL and WP_HOME.

These can be added or modified to make sure your site goes to the correct place. These are added at the beginning of the file

define(‘WP_HOME’,’http://yourdomain.com’);
define(‘WP_SITEURL’,’http://yourdomain.com’);

You can also use the relocate constant in the wp-config.php file. This will automatically updated the Site URL to be  whatever path you are using to access the login screen. This is added after the last “define” statements

define(‘RELOCATE’,true);

Note: This must be removed as soon as you have changed the site url as it leaves your website insecure.

Leave a Reply

Your email address will not be published.