Tell WordPress to use or to lose “www” for all URLs

After you get your own domain and part of the server on which you’ll host your WordPress site, you will notice that both www.example.com and example.com URL will lead to the same homepage you’ve created. While it might sound good to have both leading to your site, this isn’t the best solution when it comes to SEO.

Google itself suggests that you should decide which domain you are going to use in order for them to correctly index your site in the future. If you aren’t sure how to communicate with Google about this issue, follow these few simple steps and let Google know what your preferences are.

The most popular search engine also advises redirecting non-preferred domain visits to preferred one. And in order to do that, you should use 301 redirects, i.e. permanent redirects. This will allow your visitors to end up on your site no matter which URL they are using and you shouldn’t have problems with search engines (at least when we’re talking about URL Canonicalization).

Choose canonical URL:

While it may take you more time to decide which URL version you’re going to use, if you follow these simple steps, you’ll have your redirection done in seconds:

  1. Navigate to Settings -> General
  2. Find WordPress Address (URL) option
  3. Enter WordPress address with “www” or without it
  4. Scroll down and save changes

WordPress takes care of the rest. All the necessary redirects will be written in .htaccess file by the system and you won’t have to think about it anymore. If you chose not to use “www” in your address, every user who tries to access your site by using “www” in the address will be automatically redirected.

It doesn’t really matter which one you choose. While there will be no differences when it comes to SEO, there are slight technical differences between “www” and “non-www” URLs. We won’t go into details, but if you don’t have a few million visits per day, you shouldn’t really worry about this – simply choose the one you like better.

Redirect rules:

If you really know what you’re doing, you can write redirect rules in .htaccess by yourself. But before copying the code below, make sure you know how WordPress handles canonical redirects because you can only mess things up if you overwrite WordPress’ rules which may be already written in the file:

  1. Open .htaccess file
  2. Copy and paste one of the code, depending on which version you are going to use:
  3. Redirect non-WWW to WWW:

    #Force www:
    
    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

     

    Redirect WWW to non-WWW:

    #Force non-www:
    
    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
    
    RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
  4. Change domain name to one you own
  5. Save changes

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

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