How To Add WWW Or Remove WWW From Your Domain’s URL In The .htaccess File With Normalization Rewrite Rules

Domain URL Normalization (Standardizing WWW)

Normalizing your domain names URL with  www or without www (or automatically processing 301 redirects for permalink changes) is important when first hosting or launching a website. Without normalizing your domain’s URL in the .htaccess (hypertext access) file with rewrite rules your website will be visible from both http://www.yourdomain.com (with www) and http://yourdomain.com (without www), which creates duplicate content. Search engines like Bing and Google heavily employ URL normalization rules in order to reduce indexing of duplicate pages. If your URL is not standardized (as some call it) web crawlers will crawl the same resources twice which can fatally harm your site, and we mean harm it FAST! Google drastically penalizes websites which produce duplicate content. This is a method which search engine algorithms use to properly filter what may be spam, poorly executed content, and if the website plays it’s card right by utilizing URL normalization, importance and significance. Web browsers also perform normalization to determine if a link has been visited or to determine if a page has been cached.

CDNs and WWW

Some CDN programs require specific redirects as well. For example, our domain URL structure used to simple be botcrawl.com. If you look at our url in the address bar (depending on browser) you will notice our address starts with www. This is because of our controlled delivery network.

If we had not standardized (normalized) our URL we would have:

  • Permalinks resulting in long cached URLs  (errors)

Long Cached URL error

  • 310 errors “Too many redirects”, and  permanent 301 redirect errors.

310 error too many redirects

How To Add Or Remove www To Your Domain’s URL

Changes to your domains URL are made in the .htaccess file with rewrite rules. Hypertext access (.htaccess) files can be found in root of FTP management interfaces provided by the host (or manual). Keep in mind that .htaccess files are read on every request so changes made in directory level configuration file takes effect immediately and also, your website will still be accessible from both www.yourdomain.com and yourdomain.com.

How To Add Rewrite Rules To The.htaccess File

Down To add www to your domain name add the snippet below to your .htaccess file
Change only yourdomain.com and www.yourdomain.com below to your actual domain name’s URL.
[Normal_Box]

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

[/Normal_Box]
Down To remove www from your domain name add the snippet below to your .htaccess file
Change only www.yourdomain.com and yourdomain.com below to your actual domain name’s URL.
[Normal_Box]

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

[/Normal_Box]

To Use Or Not To Use WWW?

If you are concerned about which is better for your website, be that using www or not please identify that there is no performance or technical difference in using either setup for your domain’s URL structure. It’s the same exact webpage your’re looking at, the only difference being if that www will be visible in your web browser’s address bar… And yes that is a Shakespeare reference.

Sean Doyle

Sean is a distinguished tech author and entrepreneur with over 20 years of extensive experience in cybersecurity, privacy, malware, Google Analytics, online marketing, and various other tech domains. His expertise and contributions to the industry have been recognized in numerous esteemed publications. Sean is widely acclaimed for his sharp intellect and innovative insights, solidifying his reputation as a leading figure in the tech community. His work not only advances the field but also helps businesses and individuals navigate the complexities of the digital world.

1 Response

  1. Agnes James says:

    Thanks for sharing this helpful information. Before coming to your blog I was wondering that do URL with or without www different or effect performance of our website. But now it’s clear for me. So I decided to remove www from URL and the above code really works.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.