The Computer Oracle

Windows hosts: how can I redirect HTTPS site?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping

--

Chapters
00:00 Windows Hosts: How Can I Redirect Https Site?
00:35 Accepted Answer Score 12
01:39 Answer 2 Score 0
02:14 Answer 3 Score 0
02:26 Thank you

--

Full question
https://superuser.com/questions/951319/w...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows #https #hosts

#avk47



ACCEPTED ANSWER

Score 12


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.




ANSWER 2

Score 0


I got tricked thinking that the site serves traffic via https://example.com where in fact the URL is using a subdomain e.g. https://www.example.com In that case just add one more record to the hosts file with www.example.com like below:

127.0.0.1 example.com
127.0.0.1 www.example.com

Or in fact to avoid errors on local web server (if you are running one for development purposes)

0.0.0.0 example.com
0.0.0.0 www.example.com



ANSWER 3

Score 0


The following in your hosts file, working for me:

127.0.0.1 https://example.com
127.0.0.1 https://www.example.com