Block access to a website via http, but not https, via etc/hosts?

11,357

Solution 1

This is not possible. The HOSTS file only affects DNS requests. When your browser requests http://example.com/, the computer does a DNS lookup on example.com. When your browser requests https://example.com/, it also does a DNS lookup on example.com, and the result will always be the same for either, because they're the same. http vs https is just a different protocol.

To address your larger question of how to block it, what is your environment? Is this just a home computer, or are you doing this for a large number of computers in a corporate environment? Some more details on your needs and this situation would be helpful for solving your problem.

Solution 2

As other answers have said this cannot be done with the HOSTS file.

It can be done with Windows Firewall. Add an outbound rule to block http to the site (the default rule for outbound is allow, so you only need rules where you want to block).

Share:
11,357

Related videos on Youtube

shebang
Author by

shebang

Updated on September 17, 2022

Comments

  • shebang
    shebang over 1 year

    I want to block (not redirect) access to a website via http, but not if the user types in https.

    I am using Windows 7. How can this be done?

    • Tamara Wijsman
      Tamara Wijsman over 13 years
      What browser? Or should it be system-wide?
    • SmithsonG
      SmithsonG over 13 years
      Using the host file this is impossible unless they host ssl on another server ip address.