0

I'm trying to redirect all requests from http to https and all requests from www. to non www (https://) but no matter what i try it is not working. Specifically the redirect from https://www.example.com to https://example.com is not working. Everything else works fine. I've tried many different ways i found here on stackoverflow and other posts on the internet but none of them are working for me. When i go to https://www.example.com i get a certificate warning cause the certificate is issued to https://example.com. I'm really giving up on this one as i've tried it for two days now ...

Maybe i'm doing something completely wrong or it is something else i forgot. Help is much appreciated, thank you.

This is the code i'm using right now

RewriteEngine on
# www -> https without www
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
# http -> https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

Cheers

  • Request rewriting cannot somehow magically get you around the client side certificate validation. The initial requests goes to ``www.example.com``. If the client cannot validate the specified certificate for that request it issues an error to the user. There is no way around that. You either need an additional certificate for that host or a wildcard certificate. – arkascha Jul 26 '19 at 15:36
  • Ok yeah i get now. The rewrite is not the problem as it works when i accept the cert warning. It actually makes a lot of sense this way. Thanks for clearing that up for me. Looks like i need a new certificate. – cadelsberger Jul 31 '19 at 13:50

1 Answers1

0

Arkascha had the right answer so i'm quoting his comment:

Request rewriting cannot somehow magically get you around the client side certificate validation. The initial requests goes to www.example.com. If the client cannot validate the specified certificate for that request it issues an error to the user. There is no way around that. You either need an additional certificate for that host or a wildcard certificate.

  • What is THIS? You do not add _any_ content yourself but simply cite someone elses answer? And post that as an "answer"? Are you really certain that this was helpful? Or could it be that you only wanted to get an accepted answer? If you do that then at least have the modesty to _correctly_ cite where you stole from. Thanks. – arkascha Jul 31 '19 at 19:25