linux – Exclude subdirectory from host resolution set in /etc/hosts (with dnsmasq, or anything else)

I have a local development tool (LocalWP) that sets the path to my local environment by modifying /etc/hosts.

For example, if I set my site in Local to www.foo.com, it’ll append the following to the hosts file:

127.0.0.1 www.foo.com

This is fine, but I need to exclude a subdirectory (not a subdomain) in this domain, so it resolves to another (the original) IP.

Of course, this isn’t possible with etc/hosts because it is just a DNS pointer and doesn’t resolve anything except the domain. However, I’m wondering if there’s another tool I can use to exclude a subdirectory from the current hosts file, and point it to a new IP.

I’m wondering if something like dnsmasq can accomplish this, or if there’s another tool I could use for some conditional DNS behavior based on the resolution of the path, rather than just the domain.