How do I force my website to use/not use the "www" prefix?

To force all website visitors to use either user the www. part of the domain or not in the URL (useful for search engines) create a file called ".htaccess" then place within it (using a text editor such as notepad) one of the following two code examples below.

Be sure to replace "domain.com" with the site's domain name the .htaccess code is being uploaded too.

 

To force your site to use "www." in the URL:

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

 

To force your site to NOT use "www." in the URL:

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

 

Simply then save your changes to the ".htaccess" file and upload it within the "public_html" folder of your account.

After doing this, anyone who enters http://domain.com into the browser will be redirected to http://www.domain.com.

  • 118 Users Found This Useful
Was this answer helpful?

Related Articles

Redirect to maintenance page during upgrade using .htaccess

Redirect your visitor to maintenance page is a must when you are upgrading your site. Now you can...

How do I redirect parked domains to the main account domain using mod_rewrite?

Sometimes to protect your brand you will have several domains relating to one site however you...

Can I use mod_rewrite?

Mod_rewrite is an Apache web server module installed on all of our web servers by default, all...

How do I force a redirect from http to https?

If you want to redirect your visitors to the secure version of your site, you can use the...

Redirect to maintenance page during upgrade using .htaccess

Redirect your visitor to maintenance page is a must when you are upgrading your site. Now you can...