问题
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 Rules → Customize 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