Why You Should Set a Preferred Domain and How (WWW or Non-WWW)

pointer after http:// in blue address barA little while back a commenter reminded me of a very important optimization step I had nearly forgotten about because I’ve become so accustomed to working with WordPress, which does most of the work for you.

It’s choosing and setting a preferred domain for each website, e.g., www.mysite.com or mysite.com.

A typical WordPress installation sets it to one or the other by default, but when working with another CMS or building a site from scratch, there’s usually more tweaking involved. And even when working with WordPress you still need to doublecheck your settings for consistency.

In this article, I’ll briefly discuss what it means to set a preferred domain (also known as the canonical one), the positive impact it had on my friend’s site, and the various ways to set it up depending on which server software you’re using.

What is a Preferred Domain

Most of us consider www.mysite.com and mysite.com to be the same website address, but technically they’re different URLs.

The www prefix is actually a subdomain of the root mysite.com.

By default, most websites are configured to display the same content regardless of which version is requested by a user’s web browser. However, from a search engines perspective they aren’t always treated the same unless you specify them to be.

That’s because you can set up your website to display different content depending on which version a user requests.

From Google:

“Once you tell us your preferred domain name, we use that information for all future crawls of your site and indexing refreshes. For instance, if you specify your preferred domain as http://www.example.com and we find a link to your site that is formatted as http://example.com, we follow that link as http://www.example.com instead. In addition, we’ll take your preference into account when displaying the URLs. If you don’t specify a preferred domain, we may treat the www and non-www versions of the domain as separate references to separate pages.”

Top reasons to use a preferred domain:

  • Alleviate duplicate content issues
  • A page gets credit for backlinks pointed to either version
  • Users bookmark and share the appropriate URL
  • Control what’s displayed in the search results

Just check out how effective it was to this site’s rankings when I set a preferred domain:

keyword search engine rank report showing 4 positive ranking increases

This is a friend’s website (also one of my first ever SEO clients), and according to its ranking history report has never ranked #1 for any of these terms. Officially, I don’t do client work anymore, but as a courtesy I monitor their website and recently added it to our online SEO tools to started double checking it against our to-do checklist. Then configured their preferred domain when I saw it hadn’t been done previously.

Rankings skyrocketed within a week!

How to Set a Preferred Domain

There are a few important steps to take before setting a preferred domain.

1. First, I recommend checking to see if your site currently redirects one version to the other, or if both versions resolve.

2. After you’ve checked which version/s are resolving or redirecting, the next step is to check the source code of each to see if a canonical URL has been set.

Check the <head> section for code similar to this:

<link rel="canonical" href=”http://www.yoursite.com” />


<link rel=”canonical” href=”http://yoursite.com” />

You want to make sure these configurations aren’t negating each other.

For example, if yoursite.com is currently redirecting to www.yousite.com, then you don’t want a canonical URL set to yoursite.com.

Once you’ve determined which version you’d like to use, I recommend forwarding the other version to it using a server-side 301 redirect.

Here’s helpful sample code for redirecting all pages of a website to the preferred versions using the most common web server software.

301 Redirecting on Linux Servers Running Apache

For Linux/Apache Server configurations you’ll need to find or create an .htaccess file, usually in the root of your website, and include the following code:

# Redirecting to WWW – Apache

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,QSA]

# Redirecting to Non-WWW – Apache

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.yoursite\.com [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]

301 Redirecting on Windows Servers Running IIS7 or Later

For Windows/IIS 7 configurations you need to find or create the web.config file, also in the root of your website, and include the following code:

// Redirecting to WWW – IIS

    <rule name="Redirect to WWW" stopProcessing="true">
    <match url=".*" />
    <add input="{HTTP_HOST}" pattern="^yoursite.com$" />
    <action type="Redirect" url="http://www.yoursite.com/{R:0}" redirectType="Permanent" />

// Redirecting to Non-WWW – IIS

    <rule name="Remove www" stopProcessing="true">
    <match url=".*" ignoreCase="true" />
    <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" negate="true" pattern="^[^.]*yoursite.*" />
    <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
    <action type="Redirect" url="http://{C:1}/{R:0}" redirectType="Permanent" />

Just keep in mind your server/website may require certain features to be enabled and additional code. I just tested each of these: Joomla website on HostGator (Linux/Apache), and a basic static website on Godaddy (Windows/IIS7).

Redirecting using WordPress

I’m not sure if this will work with WordPress on IIS, but if you’re using WordPress on an Apache web server, you can choose your preferred URLs by logging into wp-admin, then going to Settings >> General >> WordPress Address (URL) / Site Address (URL).

set wordpress and web site address

I prefer the www version, so that’s how I’ve set mine here.

Now whenever someone visits seorankings.com they’re redirected to www.seorankings.com.

Setting a Preferred Version without Using Redirects

Another option is allowing both the WWW and Non-WWW version to display the same content without redirecting to one or the other. You can do this by including a canonical link element pointing to the preferred version, in the head section of each page.

However, I recommend using a redirect if possible, and only including a canonical link element to take advantage of numerous other SEO benefits.

In WordPress, the All-in-One-SEO-Pack handles canonicalization for me.

You could also use PHP or ASP redirects, but I prefer the other methods, so I won’t cover them in this article.

Setting a Preferred Domain in Google Webmaster Tools

The last thing I recommend doing is telling Google which version you’d like to use.

You’ll need a Google Webmasters account and the ability to verify ownership of each URL.

Once you’ve verified you’re the owner of both the WWW and Non-WWW version, you can tell Google your preferences under Configuration >> Settings >> Preferred domain.

setting preferred domain in google webmasters tools

Again, I’ve chosen the WWW version as shown above.

Updating your SiteMaps and Internal Links

After you’ve chosen a preferred URL and redirected the non-preferred one, you’ll want to double-check your sitemaps and internal link structure to ensure all of those links now point to the preferred version. Links pointing to either version should work, but it’s best practice to link to the preferred version throughout your site.

After you’ve set all of this up, the next time Google’s spider crawls your website and updates its index, the appropriate pages will get credit for backlinks associated with either version, and it should start displaying your preference in the search results!

That’s it!

If you have any trouble implementing this, feel free to leave me a comment below and I’ll be happy to help you out.

Share This Article With Friends!

Free eBook: A Practical Guide to SEO


Download your copy of our FREE SEO Guide and also receive valuable blog updates via email.

Leave a Reply?

free trial button

Free eBook: A Practical Guide to SEO

Free SEO eBook

subscribe to seo rankings via email Download our FREE SEO Guide and receive valuable blog updates:

subscribe to seorankings.com via rss RSS follow seo rankings on twitter Twitter - more ways to connect and subscribe.