Windows hosts: how can I redirect HTTPS site?

I have the following in my C:\Windows\System32\drivers\etc\hosts:

127.0.0.1 example.com

It works when I use: http://example.com

But does not work when I use: https://example.com, which gives error ERR_CONNECTION_REFUSED.

Any idea how to use hosts with an HTTPS site?

If not, any alternative?


The following in your hosts file

127.0.0.1 example.com

...makes both http://example.com and https://example.com go to 127.0.0.1, hence: your own machine. (Even more: anything that refers to example.com, such as ping or telnet would go to 127.0.0.1 when run from your computer.)

Apparently you have a web server running on your own computer on port 80 (HTTP), but nothing on port 443 (HTTPS). Even more, getting ERR_CONNECTION_REFUSED actually proves your hosts file is used, as otherwise you would see the default website from https://example.com.

Note that if you would have the server on your computer also support HTTPS on port 443, you'd get certificate errors, as there is no way you can buy a certificate for the domain example.com.