我尝试编辑我的 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/