views:

497

answers:

2

I've got several domains operating under a single .htaccess file, each secured via SSL. I need to force https on every domain while also ensuring www's redirect to non-www's. Here's what I'm using which doesn't work:

RewriteCond %{HTTP_HOST} ^www.%{HTTP_HOST}
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]

Example:

https://www.strategice.com

should redirect to...

https://strategice.com

Thanks in advance!

+3  A: 

Your condition will never be true, because its like "if (a == a + b)".

I'd try the following:

RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]

This will capture "google.com" from "www.google.com" into %1, the rest in $1 and after that combining the 2, when HTTP_HOST starts with www (with or without https).

Fabian
Unfortunately this still creates a "Connection is Untrusted" error when someone tries to access https://www.domain.com
radrew
Hmm but it is redirecting properly? If it is it might be a certificate issue.
Fabian
A: 

thanks for the help, it worked very well

diseño web tenerife