There might be many possibilities when you want to change the WordPress site URL.
- Completely moving your site from one domain name to another.
- when we want o to add HTTPS instead of HTTP which is migrating sight from HTTP to HTTPS.
- when you want to add www. to your site.
- Solution 1: Using MySQL Update replace query
- Solution 2: Using WordPress Plugin “Search and Replace”
There are many ways we can solve this
Note: Before doing any of the following methods please back up your database once
Solution one – Replace WordPress site URL in Database
To Replace Open your PHPMyAdmin and select the database in which you want to replace it.
This is one of the good ways to solve the URL issues. To solve and replace the URL we will be using MySQL replace() function.
Note: if you do not have a PHPMyAdmin setup then you can go to your server root and access MySQL from there.
To replace the URL you need to run the SQL Query provided below.
Be careful about your database table name prefix ‘wp_’ there are possibilities that your table prefix might be different.
In Below SQL query replace old site URL and new site URL
UPDATE wp_options SET option_value = replace(option_value, 'Existing URL', 'New URL') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, 'Existing URL', 'New URL');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'Existing URL','New URL');
UPDATE wp_usermeta SET meta_value = replace(meta_value, 'Existing URL','New URL');
UPDATE wp_links SET link_url = replace(link_url, 'Existing URL','New URL');
UPDATE wp_comments SET comment_content = replace(comment_content , 'Existing URL','New URL');
If any URL you have used inside any post or pages or attachments then extend using the below code.
UPDATE wp_posts SET post_content = replace(post_content, 'Existing URL', 'New URL');
UPDATE wp_links SET link_image = replace(link_image, 'Existing URL','New URL');
UPDATE wp_posts SET guid = replace(guid, 'Existing URL','New URL');
Solution Two – Using WordPress plugins
If you are not confident using Database you can consider this solution
Install the plugin (click here to redirect) and navigate to setting -> click search and replace menu as shown below
First, replace the main domain name
To replace all the URLs in all the database tables.
Note: enter a search keyword, replace the keyword and then select tables to replace. before the final submit, check dry run to find weather all replace are correct or not. If all correct then uncheck dry run and re-run.
Arjun is a Full-stack developer, who is fond of the web. Lives in Chikmagalur, Karnataka, India