accessing https://myIP gives unsecure connection, how to redirect to secured domain htaccess

Viewed 16

I have a SSL-certificate for my domain which works well.

However, if I go to https://111.111.111.111 (not the real IP), I get a message: Unsecure connection, certificate not trusted. Of course this is perfectly correct, because I don't have a certificate for the IP, which I will not get either (Lets Encrypt doesn't do that).

I've been puzzling with the Apache2 config files and the .htaccess file to redirect any request to https://111.111.111.111 towards my real domain https://www.example.com.

This is my .htaccess file:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^111\.111\.111\.111$
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

It works well if I try to connect to http://111.111.111.111, but not when I connect to https://111.111.111.111

My initial thought was to add:

RewriteCond %{HTTP_HOST} ^https$ [NC]

above

RewriteCond %{HTTP_HOST} ^111\.111\.111\.111$

But that doesn't work.

Any suggestions on how to fix this issue?

0 Answers
Related