How-to: Change all internal WordPress links from www to non-www

I recently changed my website’s WordPress URL from its www-version to the non www-version: changed to just 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.

  1. Backup your MySQL database.
  2. 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.
  3. Log on to phpMyAdmin or start the MySQL command line tool.
  4. Select the database you want to change all internal links.
  5. 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, '', '');
  6. Obviously, you will have to provide your own domain name instead of and decide whether you want to go from www to non-www or vice-versa.
  7. The database will report how many rows have been changed.
  8. 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.

3 replies on “How-to: Change all internal WordPress links from www to non-www”

  1. Hello, thanks for this article – however the links on my website are simply “/page” and not “” or “” and therefore work in both cases. Why would you not do something like this?

    Is there a SEO impact in having the explicitly written in the link?

Comments are closed.