For example url: www.john.com/data.txt

I can edit /etc/hosts to point www.john.com to my server's ip address let's say www.mike.com

so when edited www.john.com/data.txt will be pointed to www.mike.com/data.txt

However I want only point the absolute path. So if user enter the http://www.john.com/readme.txt it should NOT be pointed to my server.

how can I achieve that?

  • No you can't...
    – joeqwerty
    May 22, 2014 at 22:42

2 Answers 2


Host file is for host name resolution only. You can't add the path as it isn't a URL.

  • otherthan hosts file, is there any way to achieve this? May 22, 2014 at 22:43
  • @user2578106: if my memory serves me well, I once tried Kaspersky url blocker, it was able to redirect a url to its own page (with block message). So a firewall might be what you are looking for. I am not certain about this anyway.
    – boh
    May 22, 2014 at 22:57
  • A local proxy server will allow you to do this. This is probably also how Kaspersky url blocker works behind the curtain. There is probably a lot of software available that can do this; maybe someone here has experience with something specific.
    – jornane
    May 22, 2014 at 23:08
  • You are going to need some extra software. Maybe a firewall like @naive suggested. Or you could change the hosts file as you proposed and then make your webserver act as a reverse proxy for the original server and serve some specific URLs locally. But being able to do that depends on your web server features.
    – drkblog
    May 22, 2014 at 23:08

You cannot do this with /etc/hosts. It is for name resolution to ip address only. Perhaps you could do this with a local proxy server.

You must log in to answer this question.

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