How to Force www or non-www in htaccess

Many customers at some point request to force either the www or non-www version of their site to display in their visitor's browser. For example, you can have www.example.com or simply example.com display in an address bar. There is a common thought that forcing one format is better for search engine optimization. This article will guide you through how to perform this action in your .htaccess file.

You can access the .htaccess file through the cPanel File Manager or FTP Client

You are now in the text editor. Place either selection of code in the file and click on the Save Changes button at the top right corner of the screen. Be sure to replace 'example.com' with your actual domain name. NOTE: do not place both selections of code in the file as it will cause an error. 

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

 

#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Will my services be setup immediately?

As soon as your order is placed, our system will setup your account in less than 30 seconds. You...

What is your DDoS Attack protection?

A distributed denial-ofservice (DDoS) attack occurs when multiple hosts, send traffic to a target...

How can I access my email?

You can access your email via: • Webmail: Go to http://www.yourdomainname.com/webmail from any...

Do you include protection from viruses?

Yes, all our servers are protected by Clam AV.

Can I host multiple Web sites within one Shared Hosting plan?

Yes! Our Cpanel Corporate plan allow you to host more than one Website, by adding secondary...