0

I have searched S.O. over and found quite a few answers but none that address this single problem!

I am using:

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

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Both <VirtualHost *:80> and <VirtualHost *:443> are pointing to the same

DocumentRoot /var/www/public_html

WHAT WORKS

http://example.com        -> https://example.com
http://www.example.com    -> https://example.com

WHAT DOESN'T WORK

https://www.example.com   -> https://example.com

Why if both conditions are set, this fails? This comes directly from THIS PROTECTED S.O. QUESTION

What am I getting wrong here?

Zak
  • 6,976
  • 2
  • 26
  • 48

1 Answers1

0

The problem was that in my virtual hosts, I needed to add the ServerAlias of www

<VirtualHost *:443>
    ServerName example.com
    ServerAlias www.example.com
Zak
  • 6,976
  • 2
  • 26
  • 48