0

I'm using Ubuntu 18.04 with Apache.

I have the following in /etc/apache2/sites-available/000-default.conf:

<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{SERVER_NAME} =www.example.com [OR]
    RewriteCond %{SERVER_NAME} =example.com
    RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

I want to redirect all to https AND www.

These get all redirected to https://www.example.com:

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

This doesn't get redirected to https://www.example.com:

https://example.com

I also added the code with <VirtualHost *:443> but this doesn't help.

Why doesn't get https://example.com redirected to https://www.example.com?

David
  • 153

1 Answers1

0

Solution found: There's an own file for HTTPS/SSL/433 at /etc/apache2/sites-available/000-default.conf.

After I added the following code in /etc/apache2/sites-available/000-default.conf, everything is working as expected now:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
David
  • 153