Alex Rivera | Logout

apache redirect http to https and www to non www

Asked 2012-03-30T15:09:34.883
23

basically what i want is redirect al request to use HTTPS instead of http

I have this in my htaccess so far and it worked great: Code:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
</ifModule> 

today someone noticed that when going to: http://www.example.com it redirects to and shows an unsecure connection thingie.

My ssl is setup for non www domain: mydomain.com

So i need to make sure all site requests are sent to non www and https: It works fine if i put example.com it redirects to https://example.com

but with www.example.com it goes to htts://www.example.com and shows the error

what do i need to add to my code to redirect www to non www and then to ssl ?

Edit
Report

1 Answer

2

If you are using CloudFlare's free account then that's the problem. CloudFlare's free account does NOT support SSL Certificates. To continue using CloudFlare's free account with an SSL Certificate just go to the DNS settings in CloudFlare and take the orange cloud off of your domain and off of the cname WWW. That will fix your problem and cause both www and non-www to be redirected to https.

Also be sure to add this code to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Then, everything should work!

answered 2013-05-21T20:52:56.733

Your Answer