1

我试图编辑我的 HOSTS 文件以阻止特定的 url,如下所示:

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

然而,这是行不通的。

有谁知道我要去哪里错了?

4

1 回答 1

1

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

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

Fiddler 有一个规则引擎,可以通过RulesCustomize Rules访问。有大量示例供您学习,但以下脚本应该可以工作。

例如,要阻止http://www.google.co.uk主页上的徽标,您可以使用以下脚本:

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"; 
}
于 2012-08-16T12:37:07.503 回答