How to Set Your Preferred Domain (2022)

Find out why you should set up your preferred domain and how to do it.
SIA Team
July 27, 2021

Which is better: www or non-www? HTTP or HTTPS? Here’s why, and how, you should set up your preferred domain.

Hopefully, I’ll be able to easily show you how to set your preferred domain url. 

Did you know that there may already be a preferred version of your registered domain? (In fact, there could be more than one preferred domain option.) The question is: preferred according to who — the search engine crawlers? Other sites that link to you? Your visitors?

Those questions lead to the possibility that there may not just be one preferred version of your domain–but that there may be 2 (or even more), depending on whether you consider how your domain is set up (in your hosting settings), your incoming links, whether there are canonical tags on your pages, or what your .htaccess file may say.

If this seems a bit overwhelming, don’t worry. The topic of preferred domain format is actually very simple to understand, and there are some relatively simple methods available to allow you to set a preferred domain style.

What is a Preferred Domain?

You may have noticed that some website addresses are in the form of www.site.com and others are

non-www domains and don’t have the www in front (site.com). (This is usually known as the ‘dub-dub-dub’/www and ‘non-dub-dub-dub’/non-www url versions, respectively.)

You may also know that, in most cases, from the user’s perspective, it usually doesn’t matter if you see a dub-dub-dub or non-www version of a site. 

However, from a more technical perspective, setting a preferred domain can matter.

In this article, we’ll explore why it can matter, why you may want to consciously choose a preferred domain address, which options are available, and how you can go about doing your preferred domain setting. 

Why do Preferred Domains Even Matter?

Preferred domains can matter for reasons ranging from the technical (how you arrange folders and subdomains on your hosting account) to user experience. 

Why Would I Want to Consciously Set a Preferred Version of My Domain?

The key word in that question is consciously. As I mentioned before, there may be preferred versions of your domain, but they’re not the version that you would prefer, then you may wish to consciously choose a personal preference. 

Ultimately, setting a single, preferred version of your domain can be better technically and help to consolidate the ranking power of links going to different versions of your domain.

WWW or Non-WWW: Which is Better?

Should you have a www before your domain name, or not?

  • If you have subdomains (such as subdomain.maindomain.com) and/or use cookies, setting a www version of your main domain can help restrict cookies. This can be good for privacy reasons. You’ve probably seen that some sites have a cookie notice that they ask you to agree to. You could possibly have a setup where, if a visitor doesn’t agree to cookies, they’re taken to what is essentially the same page they were on, except a non-cookied subdomain of your site.
  • It used to be that some would state that the non-www version is better because people wouldn’t need to worry about the www portion, but the reality is that, in today’s Internet, for the vast majority of domains, this is not an issue. If you have a non-www, then a person who enters www will see the same version that’s on the non-www version.

HTTP or HTTPS: Which is Better?

select your preferred version

While Secure Sockets Layer (SSL) usually doesn’t come up when talking about preferred domains, I felt that I should mention it because http (or https) is part of a website’s full address. 

In case you’re not sure, HTTP means Hyper-Text Transfer Protocol. The S in HTTPS means Secure.

I think that, in the overwhelming majority of cases, HTTPS (which usually involves an SSL certificate) is preferred, because it means that any data shared between the visitor and the site is encrypted.

setup your preferred domain

A lot of web hosts offer free SSL certification. SSL can also be established with some WordPress plugins or third-party services.

Web host free SSL Certificate WordPress

At this point, you hopefully have come to a decision as to whether you’ll go with the www or non-www version of your domain.

When it Comes to Setting My Preferred Domain, Which Methods Are Available?

When it comes to setting a preferred domain, there are 3 options I know of. Keep in mind that these 3 can be combined:

  1. 301 Redirect via the .htaccess File 

This is the one I’d recommend above all, because it’s server-side and the changes you make with this method apply to your entire domain. (However, you can still use this with the other 2 methods, especially canonicalization.)

  1. Canonicalization 

Technically, this method is not as much a domain-wide preference as much as it is a page-by-page preference. That said, canonicalization has benefits similar to those of setting a domain-wide preference, so it’s something worth considering.

  1. Sitemaps. 

Although the 301 redirect and canonicalization methods are probably more important, if you really want to establish a preferred domain, you should use that version everywhere you can, including in your sitemaps XML file(s).

As a side note, it used to be that you could set your preferred domain in Google Search Console (Formerly Google Webmaster Tools), but that option isn’t available anymore. That’s not a big deal, as doing this in Search Console (or in the webmaster tools area of other search engines) would only show your preferred domain to that search engine, not the rest of the Internet.

Setting Your Preferred Domain Via .htacces 301 Redirect

If that sounds technical, that’s because…it is. Sort of. It’s not overwhelmingly difficult, but it does involve entering code in a specific location.

If your site is a self-hosted WordPress site, I have some good news: there are at least a few plugins that can help make this easier for you. I would search in the Add New area of the Plugins section for 301, redirection, or htaccess. You should see potential plugins that can help you.

.htaccess is short for hypertext access, and without going into too much detail, it basically specifies some rules that the server should follow under certain conditions (such as, in our case, how a www or non-www request is to be handled).

  1. Know what version of your domain you’d like to use (www or non-www).
  2. In a browser window (preferably desktop or laptop, as those tend to show more characters), try to see if your website’s address is a www or non-www. 
  3. (You probably already know this. I’m just mentioning this step because, afterward, I’ll ask you to repeat it, as a confirmation that this process worked.)  Take note of the version you see.
  4. Find your .htaccess file. 
htaccess location wordpress

You may have to go to your cPanel or file manager to find this. It’s usually on the root of the domain or installation.

  1. Make a (backup) copy of your .htaccess file.

Do this just in case something goes wrong. (In the following steps, you’ll be adding code to your .htaccess file, so if you later see that something’s wrong, it’ll be good to have an original file to restore.) 

There are a few ways to do this. You can just copy and paste everything in your .htaccess file to NotePad or Text Edit on your computer and save it as something you’ll remember (such as .htaccess-original). You can also just duplicate the file on your server. Just remember that it’s the one named .htaccess that will be the one that the server reads. 

  1. Open up the .htaccess file (via your file manager, FTP software, or on your local computer).
  2. If you want to set www as your preferred domain (so that non-www requests are fulfilled by www), add the following lines to the beginning of your .htaccess file: 

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

  1. If, on the other hand, you want to set non-www as your preferred domain (so that www requests are fulfilled by non-www), add the following lines to the beginning of your .htaccess file:

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

  1. Save your .htaccess file.
  2. Look at your .htaccess file in a viewer or editor (to be sure that your changes were saved). 
  3. Test your site. Go to your home page. Test out a few pages. Are they fine? (If not, you can always restore the previous version of your .htaccess file.)
  4.  On a desktop, look at your browser’s address bar: is it changed from before? Do you see a www or non-www version of your site? 

Setting Each Page of Your Domain to the Preferred (Canonical) Version of that Page

Perhaps the best benefit of canonicalization, aside from letting search engine know which is the original version of a page, is the benefit to your link building efforts. If two sites link to different versions of a page on your site (https/http or non-www/www), canonicalization effectively consolidates the flow of link juice of those links, helping with your search engine visibility and search engine rankings.

In short, instead of your incoming linking power being diluted across different versions of your page, it’s consolidated onto one version. 

(In other words, you’re hypothetically getting one definitive page with 100% linking power, rather than two pages each only having 50% linking power.)

That said, this method is simple, yet potentially tedious. 

It’s simple because it only involves adding a single line of code to a web page.

It’s potentially tedious because if you don’t have a modern content management system (like WordPress, Joomla, Shopify, and the rest) or you have a lot of page variations, you might have to establish this on specific pages. If you have a lot of such pages, the volume of work can make things quite repetitive. 

One good thing about this option is that you can also specify http or https versions of a web page. 

The steps are:

  1. Know which version of the page you want referred to as the ‘real’ page. 
  2. Whenever you’re about to edit a page’s code, it’s good to make a backup, just in case something goes wrong. 
  3. Add a canonical tag to that page, as well as all other pages that are a variation (basic copy) of that page that refer to the ‘real’ page as the one to be reference (the canonical version). 
  4. Canonical tags are, basically: 

rel=”canonical” link tag on HTML pages
OR
rel=”canonical” HTTP header

canonical tag overview diagram

As I alluded earlier, if you have a modern content management system, there may be simple solutions that allow you to establish canonicalization throughout your site. On WordPress, this can be done by any of a number of plugins.

We also have a blog post that focuses on canonicalization and has instructions on setting canonical tags on your pages, in case you opt for this option.

Sitemaps as an Attempt to Set Your Preferred Domain

If you hand-code (that is, type) your sitemaps file(s), just use the preferred version of your domain. 

That said, a lot of sitemaps files are created automatically. The reason why I mention this option last is because I think the .htaccess file determines the version of the domain that’s shown in the sitemaps file. So, by using the .htaccess method, the sitemaps file (when they’re refreshed/recreated) will likely reflect the changes you made.

Setting Your Preferred Domain Can be Worthwhile

Hopefully, the whole notion of setting your preferred domain is a bit less intimidating. Depending on your goals, doing this can be a worthy endeavor. 

Do remember that, before making changes to a files, back up that file. (Check with your host to see if they do automatic backups. I know of one that does backups every 24 hours, so if a mistake were to be made, that host could probably restore the version that was around 24 hours ago.)

Also, the methods I listed here are what I think are available to the majority of my readers. If your host’s server is different than most, or your situation calls for something customized, then do ask your technical support team for instruction. 

Hopefully, you now have a better understanding of the benefits of setting a preferred domain and how to set it for your site.

Wondering what you could do to get your site to show up for your keyword in the top of search results? Check out our other SEO articles and tests for tested information to help you get to the top.

DK Fynn
SIA STAFF SEO WRITER