Link to home
Start Free TrialLog in
Avatar of Paul Konstanski
Paul KonstanskiFlag for United States of America

asked on

.htaccess to Remove SSL and Redirect www at same time

I recently upgraded to a new SSL certificate. My old used to include both the www and naked domains (e.g. https://www.chloedog.org and https://chloedog.org).  But the new certificate only includes the naked domain.  

I'm trying to use a .htaccess redirect so that both are accomplished in one pass.  I've tried a few different things and none work.

The most recent was:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://chloedog.org/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Open in new window


With the above, the following happens:

http://www.chloedog.org?129  - Works Fine
http://chloedog.org?129 - works fine
https://chloedog.org?129 - works fine
https://www.chloedog.org?129 - I get an "insecure connection" message.

Can you tell me what I'm doing wrong? It is like it looks for the certificate before doing the redirect.
Avatar of Nathan Riley
Nathan Riley
Flag of United States of America image

Give this a try:

RewriteEngine On

# Check that you're on port 443 and the hostname starts with www
RewriteCond %{SERVER_PORT} ^443
RewriteCond %{HTTP_HOST} ^www\.

# Redirect to domain without the www
RewriteRule (.*) https://chloedog.org$1 [L,R,QSA]

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Paul Konstanski

ASKER

That is kind of what I thought... and makes sense.  Thanks for the confirmation.