Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want the hosts file to block without blocking

step 1
I've added to my /etc/host file

When I do ping I get this desired result:

64 bytes from localhost (

When I try to access in the browser, it gives me the desired error and I cannot access the site

So there is no problem with my browsers cache.

step 2
Next Ive added /itunes/ to the line above which makes

When I do ping I get the desired result

64 bytes from localhost (

BUT!!!! When I type into my browser I am able to connect to apple's itunes site, which is not expected. Writing in my /etc/hosts file should send me to when I type in my browser

//////////////// the /etc/hosts file is ignoring suburls like /itunes/ or /ipod/ but works completely fine with domains such as

Why is causing the desired result and not causing the desired result?

Don't tell me browser cache because127.0.0.1 causes the desired result.

UPDATE I have since found out that it is impossible to do what I am trying to do with the hosts file.

The /etc/hosts file can only redirect domains and con not direct pages inside those domains.

answer solved. thank you.

share|improve this question
up vote 3 down vote accepted

Host file as the name implies, is for HOST, not URL. So means nothing. It's not a host.

share|improve this answer
so it's impossible right! – Joshua Robison Apr 29 '13 at 3:29
With the hosts file? Yes. It's not fully impossible but by using the hosts file it is. What you're trying to do requires you to mess with DNS. – Will.Beninger Apr 29 '13 at 3:36
DNS or Proxy would work. – ETL Apr 29 '13 at 13:36

You are asking an impossible question.

You are asserting that the correct answer is incorrect, and that we can't tell you that.

Further, your understanding of "ping" is limited - you can't ping a URL, only an IP address or domain name. That it works at all is because it is doing some kind of truncation.

In order to understand just how far base your assertion is, you need to understand how a web page request works.

When a URL is entered into the browser, the browser breaks it down into parts, extracting the domain name. It then resolves the domain name into the IP address. (Thats where the hosts file was used).

After this, the browser connects to the IP address, and issues a "GET" command with the remainder of the URL (if its using HTTPS, it does this in an encrypted session). [ FWIW it also specifies to the web server the domain name it used so that the fileserver can support multiple domain names on 1 IP ]

The problem thus has to be in the browser itself.

Your post also appears somewhat contradictory with respect of what you put in the hosts file.

You can't correctly put a URL (or "suburl") as you called it. It is conceivable that this is where your problem occurred, but without knowing exactly what you typed in, that behaviour can't be reproduced.

share|improve this answer
are you saying that there is no way to redirect to using the hosts file? – Joshua Robison Apr 29 '13 at 3:25
I don't see why this question gets marked down since I think many other people have a similar question. How can i block without blocking and without using a proxy – Joshua Robison Apr 29 '13 at 3:27
Yes, I'm saying you can't redirect a url using a hosts file unless you do it for every url including that domain name. – davidgo Apr 29 '13 at 3:32
I marked the question down because it forbade the correct answer and was unclear. You did not ask how to block a URL without a proxy (doing that practically will require a browser plugin, or technology even harder to set up then a proxy. Maybe you should ask that as a separate question though.) – davidgo Apr 29 '13 at 3:34
the reason it's unclear is because whenever I shorten the question it is assumed that I only want to block a domain or that browser caching is the culprit . I had to get rid of all the assumptions. The simple answer to my question is that the /etc/hosts file does not work with pages inside of domains. That's my answer. I had no idea. I thought I could put inside the hosts file. but it doesnt work like that. thank you – Joshua Robison Apr 29 '13 at 3:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.