2012-08-16 71 views
1

我试图编辑我的HOSTS文件来阻止只是一个特定的URL像这样:编辑特定URL的HOSTS文件?

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

但是不工作。

有没有人知道我要去哪里错了?

回答

1

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

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

提琴手具有由规则自定义规则访问的规则引擎。 您的学习有很大的一套samples,但下面的脚本应该可以工作。

例如,以阻止对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";  
} 
+0

感谢您的快速回复,我怎么能做到这一点? – 2012-08-16 12:38:03

+0

@ user1294381我已将示例规则添加到我的答案中。 – 2012-08-16 12:41:43

+0

你有试过吗?我已经尝试过了,但仍然无法正常工作。我对JS非常熟悉,我非常肯定我已经把它放在合适的条件下。 – 2012-08-16 13:00:36