i found following Rewrite Rules, i would like to combine. They are stored in the /etc/apache2/sites-enabled/000-default.conf
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
Unfortunately it is not working together, only one of them is working.
For example: If i open http://example.com/ it redirects me to https://example.com/ If i open https://www.example.com/ it redirects me to https://example.com/
So far, so good.
But if i open http://www.example.com/ ... it does nothing.
Why?
Edit:
<If "%{HTTP_HOST} == '^www\.example\.com$'">
RewriteRule ^(.*)$ https://example.com/$1 [NC,R=301,L]
</If>
<If "%{SERVER_PORT} != '^443$'">
RewriteRule (.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
</If>
Also is not working.