Switching domain name on a wordpress

Switching WordPress Database

First, you need to create a new MySQL database on the new server and then perform the task of exporting old MySQL database from the old server to new database on the new server. You can modify all WordPress site URL’s in the MySQL database tables using PHPMyAdmin. Here are the steps to follow

Old URL – http://oldsite.com

New URL –http://newsite.com

Log into your PHPMyAdmin profile
Select the database you would like to edit
Execute the following SQL queries

#main replace
UPDATE wp_options SET option_value = replace(option_value, ‘http://www.oldsite.com’, ‘http://www.newsite.com’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;


# replace www and non-ssl
UPDATE wp_posts SET guid = replace(guid, ‘http://www.oldsite.com’,’http://www.newsite.com’);
UPDATE wp_posts SET post_content = replace(post_content, ‘http://www.oldsite.com’, ‘http://www.newsite.com’);
UPDATE wp_postmeta SET meta_value = replace(meta_value,’http://www.oldsite.com’,’http://www.newsite.com’);
UPDATE wp_options SET option_value = replace(option_value, ‘https://www.oldsite.com’, ‘http://www.newsite.com’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;
#replace www & SSL
UPDATE wp_posts SET guid = replace(guid, ‘https://www.oldsite.com’,’https://www.newsite.com’);
UPDATE wp_posts SET post_content = replace(post_content, ‘https://www.oldsite.com’, ‘https://www.newsite.com’);
UPDATE wp_postmeta SET meta_value = replace(meta_value,’https://www.oldsite.com’,’https://www.newsite.com’);
UPDATE wp_options SET option_value = replace(option_value, ‘http://oldsite.com’, ‘https://newsite.com’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;
#replace non-www
UPDATE wp_posts SET guid = replace(guid, ‘http://oldsite.com’,’http://newsite.com’);
UPDATE wp_posts SET post_content = replace(post_content, ‘http://oldsite.com’, ‘http://newsite.com’);
UPDATE wp_postmeta SET meta_value = replace(meta_value,’http://oldsite.com’,’http://newsite.com’);
UPDATE wp_options SET option_value = replace(option_value, ‘https://oldsite.com’, ‘http://newsite.com’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;
#replace non-www and SSL
UPDATE wp_posts SET guid = replace(guid, ‘https://oldsite.com’,’https://newsite.com’);
UPDATE wp_posts SET post_content = replace(post_content, ‘https://oldsite.com’, ‘https://newsite.com’);
UPDATE wp_postmeta SET meta_value = replace(meta_value,’https://oldsite.com’,’https://newsite.com’);



– Once you have modified the URL’s and table prefix, you can run the SQL query by pressing the Go button at the bottom.

The next step is updating your WordPress config file (wp-config.php) to reflect the above changes. The configuration file should be in your web document root. You need to change the username, password database name, and host values. Here are the steps to follow.


Updating your wp-config.php file

Using your hosting account editor, open your wp-config.php file.
Add two lines to the file which defines the new location of your website.
define(‘WP_HOME’,’http://mynewsite.com’);
define(‘WP_SITEURL’,’http:// mynewsite.com’);

Locate for a section that looks like this

define(‘DB_NAME’, ‘yourdbnamehere’);

/** MySQL database username */

define(‘DB_USER’, ”usernamehere’);

/** MySQL database password */

define(‘DB_PASSWORD’, ‘passwordhere’);

/** MySQL hostname */

define(‘DB_HOST’, ‘localhost’);

Note – enter the database information from your database as follows

yourdbnamehere= your MySQL database name
usernamehere is your MySQL Database Name
yourpasswordhere is your MySQL Password
localhost is your MySQL Host Name

Save modifications to wp-config.php file

source

2020-10-15 18:53:40

Comments

Add a Comment

Login or Register to post a Comment.

Homepage