0

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?

2 Answers2

2

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

drkblog
  • 2,655
  • otherthan hosts file, is there any way to achieve this? – user2578106 May 22 '14 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 '14 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 '14 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 '14 at 23:08
1

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.

nettux
  • 201