0

I have a website like subdomain.domain.com with a https certificate. I want redirect everything to my subdomain in https without www. I use the following code in my htaccess file.

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

This works for

http://subdomain.domain.com -> https://subdomain.domain.com
http://www.subdomain.domain.com -> https://subdomain.domain.com
https://subdomain.domain.com -> stays as it is (good)
https://www.subdomain.domain.com -> ERR_SSL_PROTOCOLL_ERROR

Any idea what I have to add to redirect like that:

https://www.subdomain.domain.com -> https://subdomain.domain.com
Martin
  • 11
  • 2
  • In order to respond to https:// request for a domain name, you need to have the certificate for that domain name (you need it even if you only want to do the redirect!). – Dusan Bajic Aug 10 '19 at 09:50
  • I have the certificate for the domain, that is not the problem. The redirect from http to https works perfectly. The only redirect that does not work is the one where the user puts in https with www. – Martin Aug 10 '19 at 09:54
  • You have certificate for "www.subdomain.domain.com"? – Dusan Bajic Aug 10 '19 at 09:55
  • I have a certificate for *.domain.com (the main domain and the subdomains). – Martin Aug 10 '19 at 09:59
  • That does not include `www.subdomain` because of the dot.... – Dusan Bajic Aug 10 '19 at 10:00
  • https://stackoverflow.com/questions/26744696/ssl-multilevel-subdomain-wildcard – Dusan Bajic Aug 10 '19 at 10:01
  • This clears it up, thanks! So the www. is in a way treated like a subdomain? That is the reason why www.domain.com and subdomain.domain.com works, but www.subdomain.domain.com does not work? – Martin Aug 10 '19 at 10:06
  • Yes, you are correct. – Dusan Bajic Aug 10 '19 at 10:07
  • Thanks a lot. I would have never thought of that… At least now I know why it does not work. I hope that nobody tries to put that into the browser line... – Martin Aug 10 '19 at 10:10

0 Answers0