0

I am trying to block this website https://example.com/en/b9ah using the hosts file.

I went to file explorer, This PC, Selected Windows, System32, drivers, Etc, Host File, copied host file and pasted it on my desktop, and opened that copied version in Notepad.

I typed (0.0.0.0 https://example.com/en/b9ah) there is no www, only https://.

I saved the file I closed out of Notepad, I selected the copied version on my desktop, I dragged it into the file explorer with host file, dropped into the window, and got the message do you want to replace, I confirmed the replacing, I confirmed administrator access, I then opened the original host file, to make sure my changes were there and they were.

Before anyone suggests restarting my computer or deleting cache or cookies, I also set another website as a test:

www.another.com =0.0.0.0 www.anotherexample.com

This site which has old cache and cookies still of it was blocked after repeating the same process as the site I actually want to block.

But the website I want to block is not blocked.

So that has brought me to the conclusion that the issue is the URL I used in the hosts file. What is the correct way to add this site to the hosts file in order to block it?

I did 0.0.0.0 example.com like I was told and it still did not work:

enter image description here

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

localhost name resolution is handled within DNS itself.

127.0.0.1 localhost

::1 localhost

0.0.0.0 example.com

Like this:

And this:

What am I doing wrong?

Giacomo1968
  • 58,727

3 Answers3

5

"https" is not a website. It is a protocol. The protocol prefix does not belong in your hosts file. The hosts file provides paths to hosts -- it doesn't provide paths to protocols like "https" or "plain text".

Albin
  • 11,950
user165568
  • 926
  • 5
  • 16
3

@user165568 is 100% correct - to clarify what he is saying - in the "hosts" file you can block "example.com" to block any url associated with that domain (you would need a seperate entry for www.example.com to block the www version).

If you are looking at blocking more specifically then the domain name level you will need an alternative strategy like a "URL Blocker" plugin for your domain.

For the sake of clarity, this has no specifics related to the original domain you put in.

davidgo
  • 73,366
3

Is there any way to block this website with host file that I'm just not doing correctly?

The entry in your host file seems to be correct. When you type in the address or refresh the website and is still loading it means your browser fetches the data from the cache.

Please try to reload the website including the cache, usually with Crtl+F5 (e.g. with Chrome, Firefox, etc.) which should do the trick.

Unless there is another problem like you forgot to save the hosts file, a DNS cache issue etc. then this solution won't work. Do a ping test to check for other problems:

  • ping example.com (without the hosts file entry)
  • add the hosts file entry (e.g. 0.0.0.0 example.com)
  • ping example.com again

Let us know the results of the ping test if the problem prevails.

its just https:

https:// is not part of the domain name. You can ignore it for all intents and purposes when you work with the hosts file. But you can not ignore other prefixes like www. Anything before the top-level domain (e.g. .com) and after the protokoll SomeProtokoll:// is relevant. Note that www.something.com and something.com need to be 2 separate entries in your hosts file.

I'm starting to wonder what's the point of relying on host file to block websites when this piece of crap can only do limited ones with www. in their URL

It is not limited to sites with www as a prefix and it's not a piece of crap. It just wasn't intended for blocking websites. Its purpose is to map IP addresses to domain names (e.g. if you want the domain to be resolved to a different IP than provided by DNS server or if a DNS Server is not available). You can use it to block websites but it will remain a workaround that might not meet all your requirements. (The hosts file is actually the predecessor of DNS)

Additional Thoughts: You might want to consider rerouting to 127.0.0.1 instead of 0.0.0.0 and maybe even adding a local HTTP-Server that shows "This site is blocked". But honestly, I would use a 3rd party application (see here) or the firewall (if you are using one) for blocking.

Albin
  • 11,950