WWW or Non WWW: The Quick Fix with .Htaccess

It’s always interesting to stumble upon new websites and still see both the two variants of www. and non-www still accessible.

You might have noticed that some websites use the prefix www. and some don’t. While this isn’t a do-or-die issue, it is best practice to ensure that only one variant is accessible.

Not only will your website look much neater, but search engines will also be able to index and display your page’s URLs more consistently. It’s a win-win in all cases.

SEO Benefits: WWW or non-WWW

To be perfectly clear, there are no SEO benefits of choosing over the other. Google has also stated that it’s a personal preference thing.

Personally, I like the www. and think it works great in occupying more room on the search engine result pages.

You might have also noticed that the Red Search website uses www. Choose what you like, and we’ll move on to implementing the fix.

The Quick Fix

One simple way of fixing this issue is to implement a 301 redirect to the address of your choice. You can do this by adding a short line of code into your .htaccess file.

A website’s .htaccess file is typically located in the root folder of the website’s hosting server.

To find this file, you’ll need access to your FTP client. Once you’ve gained access, navigate your way through to /public_html/. Locate and open the .htaccess file. You’ll want to put in your 301 redirect code once the .htacccess file is opened.

WWW .htaccess Code

Okay, let’s say you want to keep the www. Copy and paste the code into the top of your .htaccess file.

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} !^www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Non-WWW .htaccess Code

However, if you feel your domain may look cleaner without the www, simply whack in the following code:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} !^example.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]

After applying this code, you’ll want to wait a minute or two before testing the URL. Depending on which code you’ve used, your URLs should now be redirected as intended.

If you run into any problems, feel free to drop a comment below.



Written by



Our most recent blog posts. Check them out!

    Contact Us

    Keep up with the latest