大网数据广告活动
服务器运维问答

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

· 52CE 我爱测

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.…

问题原文

原帖链接 · Orun · CC BY-SA 4.0

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.

已采纳解答

原帖链接 · Massimo · CC BY-SA 4.0

You can't do that.

Name resolution is handled by DNS (or /etc/hosts, or dnsmasq, or whatever else), but everything after the first / is part of the HTTP protocol, and as such is handled by your web browser (on your side) and the web server (on the other side); DNS (or /etc/hosts, or dnsmasq, or whatever else) is only used to find the IP address associated with the host name, which will always be the same regardless of the subdirectory you are trying to access; the actual HTTP path will only be used after the connection is established.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-12-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。