windows - 编辑特定 URL 的 HOSTS 文件?

标签 windows hosts

我尝试编辑我的 HOSTS 文件以仅阻止特定网址,如下所示:

127.0.0.1 google.com/pagetoblock
127.0.0.1 www.google.com/pagetoblock

但是这不起作用。

有人知道我错在哪里吗?

最佳答案

您的 HOSTS 文件仅允许您设置(顾名思义)主机的 IP 地址(例如 google.com 或 www.google.com)。您无法为特定页面设置 IP 地址。

您可以使用 Microsoft Fiddler 等工具来设置特定 URL 的 IP 地址,但这需要 Fiddler 持续运行。

Fiddler 有一个通过规则自定义规则访问的规则引擎。 有一组很棒的samples供您学习,但以下脚本应该可以工作。

例如,屏蔽 http://www.google.co.uk 上的 Logo 主页,您可以使用以下脚本:

if (oSession.url == "www.google.co.uk/images/srpr/logo3w.png"){
    // Prevent this request from going through an upstream proxy
    oSession.bypassGateway = true; 
    // Rewrite the IP address of target server
    oSession["x-overrideHost"] = "127.0.0.1";  
    // Set the color of the request in RED in Fiddler, for easy tracing
    oSession["ui-color"]="red"; 
}

关于windows - 编辑特定 URL 的 HOSTS 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11987245/

相关文章:

python - 我应该抛出哪个 Python 异常?

c++ - 创建子进程

linux - Debian 命令行无法解析主机

apache - 在单个服务器 (IP) 上为多个域(虚拟主机)设置 SSL

Vagrant:不要将主机名映射到/etc/hosts 中的环回地址

windows - 安装 fugitive.vim 插件后,Vim 在 Cygwin 下启动非常慢

C++:SIGINT后继续执行

azure-devops - Azure devops 托管代理可疑主机文件

windows - 仅在单个端口 8080 上转发到本地主机(windows)可能吗?

c++ - USB插入时自动运行