I have Let’s Encrypt SSL certificate for exampledomain.com. www.exampledomain.com redirects to https://exampledomain.com, but exampledomain.com gives “Apache2 Ubuntu Default Page”. I use following .conf file for domain in sites-available
folder:
<VirtualHost *:80>
DocumentRoot /var/www/html/mydomain
ServerName mydomain.hu
ServerAlias www.mydomain.hu
RewriteEngine on
RewriteCond %{SERVER_NAME} =mydomain.hu [OR]
RewriteCond %{SERVER_NAME} =www.mydomain.hu
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Redirect / https://mydomain.hu/
</VirtualHost>
EDIT:
Modified .conf
file with use of answers.
<VirtualHost *:80>
DocumentRoot /var/www/html/mydomainamehu
ServerName mydomainame.hu
ServerAlias www.mydomainame.hu
RewriteEngine on
RewriteCond %{SERVER_NAME} =mydomainame.hu [OR]
RewriteCond %{SERVER_NAME} =www.mydomainame.hu
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Redirect / https://mydomainame.hu/
</VirtualHost>
<VirtualHost *:80>
ServerName mydomainame.hu
ServerAlias www.mydomainame.hu
RewriteEngine on
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [R,L]
</VirtualHost>
<VirtualHost *:443>
ServerName mydomainame.hu
Redirect 301 / https://mydomainame.hu/
</VirtualHost>
<VirtualHost *:443>
ServerName mydomainame.hu
DocumentRoot /var/www/html/mydomainamehu
</VirtualHost>
2
Answers
VirtualHost must listen on port 443 when using https.
I usually listen on port 80, add a redirect there and then config the docroot in a separate VirtualHost:
Please note that you should also add access rules and certificates configuration (if needed), otherwise this is not going to work.
You may use a redirect rule like that: