Force www on all your domains, or not...

  Previous article Next article  

Force www on all your domains, or not...

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.2
  Last updated: 13-02-2017
  Comments: 0

A generic piece of code you can drop in all of your root .htaccess files to force www., or do the opposite and remove the www. in the URL no matter what the domain name is.

The method described here originates from the IDT blog and was written by Manuel in 2012.

  How to use

To avoid SEO and cookie issues you can set up your website with or without "www." in the URL. The code below will work on any domain name so it's really easy to include it in your "default" root .htaccess file.

Check the following article for use with: HTTPS »

Preferring http://www.website.com

# Link to http://website.com then redirect to http://www.website.com
<IfModule mod_rewrite.c>
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

Preferring http://website.com

# Link to http://www.website.com then redirect to http://website.com
<IfModule mod_rewrite.c>
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>

A2 Webhosting CMS Made Simple

  Working example



A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  0 Comments

No comments yet...

CMS Made Simple 2.2.2 - Tutorials, tips and tricks - CMSMS 2.2.2

Force www on all your domains, or not...

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.2
  Last updated: 13-02-2017
  Comments: 0

A2 Webhosting CMS Made Simple