Portal Home > Knowledgebase > Using CloudFlare > Modify your .htaccess to force traffic to www

Modify your .htaccess to force traffic to www

Once you've activated CloudFlare on your domain.com this domain is being speed up and protected by CloudFlare, but only the 'www.domain.com' format, not 'domain.com' as well.
If you have sub-domains such as 'sub1.domain.com' , 'sub2.domain.com' , 'etc.domain.com' you can enable CloudFlare on those without any problems.
But the simple 'domain.com' will remain unprotected.

How to fix this?
You can modify your .htaccess file from your root 'domain.com' folder to force all the traffic to use 'www.domain.com' instead of 'domain.com'
You can do this by adding this piece of code to the .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

This piece of code will make sure that people accessing your 'domain.com' are quickly redirected to 'www.domain.com' (the one speed up and protected by CloudFlare)

If you need assistance setting this up be sure to contact our Support Deppartment.

Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
Getting Started (Views: 1782)
How does it work? (Views: 1922)

scroll up