1

I have modified my Windows 10's hosts file to add an entry for a URL to lead to a given IP, as is it's intended usage.

However, this only works for connecting on http. Trying to enter the site through https does not work. Can this be solved?

2
  • What browser are you using?
    – dirdi
    Commented Dec 11, 2019 at 0:19
  • 4
    Hosts file entries are not URLs, they are mappings from hostnames (including fully qualified domain names) to IP addresses. If you can't connect to a host via HTTPS, it usually indicates that the host does not have an HTTPS server listening on port 443. So the solution would be to reconfigure your web server process to listen on port 443 and for it to require TLS for connections on that port.
    – Spiff
    Commented Dec 11, 2019 at 0:23

1 Answer 1

4

The hosts file is for domain name resolution, which is a process that takes domain names and converts them to IPs.

I have modified my Windows 10's hosts file to add an entry for a URL to lead to a given IP,

No you didn't. What you added are host entries. They only contain an IP and domain name.

127.0.0.1    localhost
192.168.0.1  my.home.router

URLs look like this:

https://www.google.com

https://some-weird-site.example:1234/path/to/file

Now that we got that out of the way ...

Trying to enter the site through https does not work. Can this be solved?

Not unless you control the destination IP's webserver. Here's why:

So let's say I do this in my hosts file:

192.168.0.1 google.com

This means when I enter "http://google.com" in my browser, my browser will issue an HTTP request to 192.168.0.1 over the standard HTTP port (80). If I have a web server running on 192.168.0.1 and listening on port 80, it will load.

When I enter "https://google.com" in my browser, my browser will issue an HTTPS request to 192.168.0.1 over the standard HTTPS port (443). If I didn't set up my web server to deliver an HTTPS site on port 443, nothing will load and you'll see an error in your browser.

Can I make whatever is at 192.168.0.1 do anything different just by changing or setting anything in hosts file? No. Can you redirect ports in the hosts file? No. Can you redirect full URLs or change protocols in the hosts file? No.

You have to be in control of the software running on 192.168.0.1 to do anything like that.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .