I was searching a lot on this topic, but non of the threads I found worked for me. I want to have a proper permanent rewrite rule for the following:
http(s)://anysubdomain.domain.tld(/) -> https://www.domain.tld
http(s)://domain.tld(/) -> https://www.domain.tld
http(s)://anysubdomain.domain.tld/foo/bar(/) -> https://www.domain.tld/foo/bar
http(s)://domain.tld/foo/bar(/) -> https://www.domain.tld/foo/bar
Anything I tried up to now doesn't capture all subdomains or causes a redirect loop or redirects more than once...
Currently I'm running this, just to have at least www and https:
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$ [OR]
RewriteCond %{HTTP_HOST} (?!^www\.)^(.+)$
RewriteRule (.*) https://www.domain.tld/$1 [R=301,L]
Thanks in advance.