2

Ok, I know how to redirect a normal page using the "host" file but it doesn't work for certain pages like http://rustledjimmies.com/ or http://heyyeyaaeyaaaeyaeyaa.com/

For example, I want to redirect youtube.com to rustledjimmies.com/. But after I do the things I usually have done to redirect, it just doesn't work.

Any ideas why and how to fix it?

Here's an example which I have put into "hosts" file.

104.36.80.4 fb.com

The IP Adress is for the site rustledjimmies.com but somehow when I write it into "hosts" it shows up a different website.

205.186.179.191 fb.com

This one is for the heyyeyaaeyaaaeyaeyaa.com but it doesn't respond at all (for me atleast)

4
  • Did you flush the dns cache on the workstation? cmd > ipconfig /flushdns
    – Sun
    Commented Feb 18, 2015 at 21:33
  • Nope, it doesn't work.
    – Linas
    Commented Feb 18, 2015 at 21:47
  • 1
    What are you putting in your hosts file? Please include the relevant lines in your original question.
    – heavyd
    Commented Feb 18, 2015 at 21:53
  • I notice you've tried to edit from another account - please register an account and use the contact us link to get all three merged.
    – Journeyman Geek
    Commented Feb 18, 2015 at 23:37

1 Answer 1

7

It won't work for some sites.

Hosting one site per server (or per IP address) is not a good idea for small websites. Hosting multiple websites on one IP address is possible, this feature is called virtual hosts.

But the server has to somehow check which site you're willing to open. HTTP protocol specification defines has a Host header (which is mandatory since HTTP 1.1) which contains address of the website your browser is requesting. This header is used by the server to select appropriate virtual host.


Here's a normal request to YouTube:

  • Enter http://youtube.com in the address bar and press Enter
  • Your computer queries DNS server to resolve youtube.com domain name to IP address.
    • DNS server's response: 46.28.247.104
  • Browser sends a HTTP request to 46.28.247.104:

    GET / HTTP/1.1
    Host: youtube.com
    
    • Server at 46.28.247.104 recognizes youtube.com as its virtual host and serves it to you.

Now let's assume you've mapped youtube.com to 192.168.0.100 using the hosts file.

  • Enter http://youtube.com in the address bar and press Enter
  • youtube.com's IP is provided in hosts file, so no DNS lookup is required.
    • System tells browser that youtube.com's address is 192.168.0.100
  • Browser sends a HTTP request to 192.168.0.100:

    GET / HTTP/1.1
    Host: youtube.com
    
    • Server at 192.168.0.100 doesn't recognize youtube.com as its virtual host, so it responds with 404 error code.
1
  • +1 excellent use of examples when it works and when it does not
    – Sun
    Commented Feb 18, 2015 at 23:31

You must log in to answer this question.

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