I recently changed my website’s WordPress URL from its www-version to the non www-version: www.trick77.com changed to just trick77.com. As this may will confuse search engines and thus lower your visibility in organic searches, it’s recommended to configure a 301 (permanently moved) redirect from the old domain name to the new one. There’s lots of SEO information about redirecting domain names using mod_rewrite and .htaccess to be found on the web.
Now, some SEO experts claim that it’s important to change the internal links on a web site as well. As I’m occasionally linking to my own WordPress posts within my web site, all those links still point to the old www version of the domain name. So, is there an easy way to change all internal links from one domain name to another on a WordPress site at once?
Fortunately, there is, at least if you’re using MySQL.
- Backup your MySQL database.
- Did you really make a backup of the database? Just imagine all the hassle you will be going through if something goes wrong with the internal link update.
- Log on to phpMyAdmin or start the MySQL command line tool.
- Select the database you want to change all internal links.
- Run this query. In this example, I’m changing all internal links in the posts or pages of my website from the www to the non-www domain name.
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://www.trick77.com/', 'https://trick77.com/');
- Obviously, you will have to provide your own domain name instead of trick77.com and decide whether you want to go from www to non-www or vice-versa.
- The database will report how many rows have been changed.
- Verify that the links on your WordPress site have changed using your web browser. You may want to empty your browser cache first and also make sure you empty the WP super cache if you’re using that plugin on your WordPress site.