Editing HOSTS file for specific URL?

本秂侑毒 提交于 2019-12-11 06:25:34

问题


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

However that isn't working.

Does anyone know where I'm going wrong?


回答1:


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.

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 has a rules engine accessed by RulesCustomize Rules. There is a great set of samples for your learning, but the following script should work.

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


来源:https://stackoverflow.com/questions/11987245/editing-hosts-file-for-specific-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!