How to fix errors & change all WordPress links to a new domain or when uploading a WordPress site from localhost to Hosting/VPS. In these cases, you may encounter errors related to links (URLs) on your website. This occurs because WordPress stores links as absolute URLs, including the domain name or the website’s path.
2 Method Fix Errors & Change All WordPress Links to a New Domain
For example, if you are testing (dev) a website on localhost, the link of the domain name is “http://localhost/wordpress”, it will not work on the server. Therefore, you must change the faulty WordPress domain name to the official domain like (http://domain.com) for your website to work.
Method 1. Fix wordpress Link/URL error with All-in-One WP Migration plugin
Download All-in-One WP Migration Unlimited Full Extensions plugin latest version. This is a powerful tool that allows you to easily backup or migrate your WordPress website data from localhost to hosting/VPS or from one server to another, especially it will help you fix WordPress link errors or change all WordPress links to a new domain.
The steps are very simple, you install the plugin and use the “Export” function to backup the old website. Then you install a new wordpress site on your hosting or VPS and install the All-in-One plugin on the new site. Finally use the “ Import ” function and find the backed up file and execute “Import”. With this plugin all the URLs of the old domain will be changed to the new domain. Your website should work as expected without any problems.
Method 2. Change, edit URL in wordpress using SQL statement
If you have manually uploaded the source code and imported the database on the Server, you can also fix the WordPress link in your database so that the domain name is changed. You can use phpMyadmin, or login to MYSQL using any method to your knowledge and execute SQL statement to change your wordpress site URL.
1. Use MYSQL to change URL
Login to MYSQL, if you are using VPS you can use SSH to connect to Server and then login to MYSQL. On some Hosting there is also SSH login function.
mysql -u user -p use database_name;
- User: is the username that is managing the database of the current website, enter the password when asked.
- Use: is the command to select the database you want to perform, this is how to fix errors, edit URLs in wordpress that ItsmeIT often does.
Next, you copy the SQL command to change all WordPress links to a new domain and fix the old domain name and the new domain name for these statements:
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl'); UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl'); UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
- The old URL must be entered correctly including http or https, the new domain name too, you need to enter the correct Link/URL.
- “wp_” is your database prefix you need to check and change if your database uses a different prefix.
- If you are not sure with your SQL code you can click open this tool to generate and edit the code to change all WordPress links to a new domain.
After you have fixed the above statement, open MYSQL again and run the corrected statements to update the new URL for your site. Once done, clear your browser cache and check again that your website is working correctly with the URL.
2. Login phpmyAdmin to change WordPress domain name error
If you use hosting and have Cpanel, there is usually a database manager available with phpmyAdmin , Open phpmyAdmin, select the database you want to execute, then select SQL and run the WordPress link fix command in step 2 as shown below.
In the image above, I changed the WordPress domain that failed from www to a URL without www. Similar to step 2, after successfully running the command, delete your browser history and visit your website again, now it has updated the URL to the new domain name.
There are two ways to fix and change all WordPress links to a new domain when you migrate servers or move from localhost to a server, or when you change the domain name. If you are new to this process and encountering difficulties with the domain change, It’smeIT recommends the first method as it is safer and hassle-free. How did you handle this situation? Feel free to leave a comment below.