Change WordPress URL

Method 1: Editing MySQL backup

To change WordPress site url, backup your MySQL database.

mysqldump -u USERNAME -p WP_DB_NAME > db.sql

Run sed command to replace the URL in MySQL backup file.

sed -e 's/OLD_URL/NEW_URL/gi' db.sql > db-modified.sql

Restore the new db-modified.sql, that will have the database with URL changed.

mysql -u USERNAME -p WP_DB_NAME < db-modified.sql

Method 2: Using Plugin

Edit your wp-config.php and add following line.

define('WP_HOME','https://yourdomain.com');
define('WP_SITEURL','https://yourdomain.com');

if you want site avialble on multiple URL

define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/');

You can also edit the wp_options table

update wp_options set option_value="https://yourdomain.extn" where option_name="siteurl" or option_name="home";

Now you need to use some wordpress plugin to change URL in database, here are some useful plugins for changing site url.

See WordPress

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *