Useful Web & Tech Tutorials and Tips

How to Add www. to Your Website's Domain Name

Posted in Domains / 10 Mar, 2014

Last Updated: May 28, 2025

Wondering how to add "www." to your domain name for URL consistency and SEO? This guide explains why choosing between www and non-www from the very beginning matters, and shows you how to configure your domain properly using a simple .htaccess file redirect.

How to Add www. to Website Domain Name

When you first register a domain name and launch your website, it often defaults to a non-www version, like

http://example.com

However, many site owners prefer their URLs to include www. at the beginning, like

http://www.example.com

This raises a common question: should you use the www or non-www version of your domain? From a technical and SEO perspective, both are valid, but consistency is crucial. Search engines treat http://example.com and http://www.example.com as separate entities, or as separate domains let's say. If you don't handle redirection properly, your website could suffer from duplicate content issues or lose valuable backlinks.

In addition, if you use one version but don't redirect the other, users who type the alternate version manually may see an error or fail to reach your site entirely; which means a loss of website visitors. For instance, if your site is accessible only via http://example.com and someone tries to visit http://www.example.com, they might encounter a blank page or server error, unless you've set up a proper redirect.

To avoid these issues, it's important to choose a preferred version, www or non-www, and redirect all traffic to that version. In this guide, we'll show you how to add www. to your domain name and ensure all non-www traffic is automatically redirected to the www version.

Why You Should Use www or non-www Consistently

While the choice between www and non-www is largely a matter of preference, there are some practical and technical differences:

  • SEO consistency: Search engines treat them as separate URLs, which may split your ranking signals if both are accessible without redirection.
  • Cookie handling: In complex setups with subdomains, using www can help limit the scope of cookies, improving performance.
  • DNS flexibility: Some advanced DNS configurations are easier to implement when using www.

The bottom line: Pick one version and stick with it. If you prefer to use www, follow the steps below to implement a redirect and ensure consistency.

How to Redirect to www Using .htaccess

To force your website to use the www version of your domain, you'll need to add a simple redirect rule to your .htaccess file. This file sits in the root directory of your site and controls how your web server handles requests.

Step 1: Locate Your Website's Root Directory

Using your hosting control panel (like cPanel or DirectAdmin), access your site's root directory:

  • If your domain is your main domain, the root folder is typically the public_html folder.
  • If your domain is an addon domain, navigate to the specific folder created for it.

Step 2: Find or Create the .htaccess File

Look for a file named .htaccess in the root directory. If it doesn't exist, create a new file named exactly as .htaccess (no prefix).

You can create or edit this file using File Manager in cPanel or through an FTP client like FileZilla. Make sure hidden files are visible in your File Manager, as files starting with a dot are often hidden by default.

Step 3: Add the Redirect Code

Insert the following code into your .htaccess file to redirect non-www traffic/requests to the www version of your site:

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

Explanation:

  • RewriteEngine On enables the rewrite module.
  • RewriteCond checks if the request is for the non-www domain.
  • RewriteRule redirects the request to the www version using a 301 permanent redirect.

Step 4: Customize the Code for Your Domain

Replace example.com in the code above with your actual domain name. Once done, save the file and upload it back to your server if necessary.

Step 5: Test the Redirect

After saving the changes, open a browser and type in your domain without www. If everything is configured correctly, it should automatically redirect to the www version.

For example, typing http://example.com should redirect to http://www.example.com.

Additional Tips

  • Use HTTPS: Make sure your SSL certificate covers both www and non-www versions to avoid browser security warnings. You can also modify the redirect to force HTTPS and www together.
  • Update Google Search Console: If you use Google Search Console, make sure to add both versions of your domain (with and without www) and set the preferred domain.
  • Check for duplicate content: Use SEO tools like Ahrefs, Moz, or Screaming Frog to verify that only one version is indexed by search engines.

How to Force www and HTTPS in One Redirect

If you want to redirect both non-www and non-HTTPS traffic to the secure www version, use this version of the code:

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

This ensures all traffic goes to https://www.example.com no matter how the user types it.

Choosing between www and non-www may seem trivial, but it has important implications for SEO, site consistency and user experience. Once you've made your choice, implementing a redirect using .htaccess ensures that all visitors and search engine crawlers land on the correct version of your domain.

If your goal is to use the www version, follow the steps explained above to make a quick and permanent change. It only takes a few minutes, but it can prevent a host of long-term issues and help consolidate your website's authority online.

f t g+ in