编辑特定 URL 的 HOSTS 文件? [英] Editing HOSTS file for specific URL?

查看:58
本文介绍了编辑特定 URL 的 HOSTS 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have tried to edit my HOSTS file to block just a specific url like so:

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

然而这行不通.

有人知道我哪里出错了吗?

Does anyone know where I'm going wrong?

推荐答案

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

Your HOSTS file only allows you to set the IP address for (as the name suggests) the host (e.g. google.com or www.google.com). You cannot set the IP address for specific pages.

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

You could use a tool like Microsoft Fiddler to set the IP Address for specific URLs, but this would require Fiddler be running continuously.

Fiddler 有一个由 Rules 访问的规则引擎 →自定义规则.有一组很棒的示例供您学习,但以下脚本应该有效.

Fiddler has a rules engine accessed by RulesCustomize Rules. There is a great set of samples for your learning, but the following script should work.

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

For example, to block the logo on the http://www.google.co.uk homepage, you could use the following script:

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"; 
}

这篇关于编辑特定 URL 的 HOSTS 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆