Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm working locally on a project and want to have some requests to a domain resolve to localhost and others just go where they normally would.

I want to essentially do this in my hosts file:

86.75.3.09 www.example.com/dir/*
127.0.0.1 www.example.com

As far as I understand, this isn't possible with /etc/hosts, but I could be wrong. Nevertheless, I'm open to suggestions. I'm using Apache and have tried using a proxy to send /dir/* requests to the real IP address of www.example.com, but then they can't resolve where I came from—I need it to seem like I'm accessing www.example.com by going directly to www.example.com.

I.e., this doesn't do what I want in my site configuration:

ProxyPass /dir/ https://86.75.3.09/dir/

Because then the foreign site thinks I'm accessing it from 86.75.3.09 and not example.com.

share|improve this question

1 Answer 1

As far as I understand, this isn't possible with /etc/hosts, but I could be wrong

You understood that correctly.

DNS (and /etc/hosts is part of the DNS resolver) resolves hosts.
It does not do anything with URLs.

In 86.75.3.09 www.example.com/dir/* is not the name of a computer/host, so it should throw an error or ignore the line.

This is normal DNS operation and this is just how it works.

Confusingly HTTP is an odd duck. the HTTP protocol does look at server names and directories. The host will use DNS to resolve the IP, and then sent a datagram which includes the URL. This is why you can have different rules for different directories when you play with proxies (or even multiple website domains on a single IP).

But as written before. HTTP is the odd duck here. And first it will need to resolve the IP via DNS.


I pondered posting this as a comment since it does not really help you with the problem, other then understanding where things go wrong. Sadly comments do not allow a lot of formatting. :(

share|improve this answer
    
Good information, and solidifies a few of my assumptions. Thank you. Is it possible to set up something like a DNS interceptor to catch certain domains? –  Ian Hunter Apr 6 '13 at 15:48
    
You might be able to do something with a proxy like squid. That way you have something which understands HTTP and you may be able to redirect some of the domains. However that is outside my experience and does not involve the host file. You might want to check if there are similar posts and if there are none create a new post. –  Hennes Apr 6 '13 at 16:01

Your Answer

 
discard

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.