Squid url_rewrite_program

為{幸葍}努か 提交于 2020-01-17 06:13:06

问题


I would like to use the squid url_rewrite_program to get rid of adf.ly ads. I've already written a perl script on which I've taken the code from an example and this works fine. However I can't get it working in squid it just seems as it isn't doing anything?

I've tested the perl script via the command line and output looks exactly as I want it.
Can somebody help?

#!/usr/bin/perl
use strict;

# Turn off buffering to STDOUT
$| = 1;

# Read from STDIN
while (<>) {

my @elems = split; # splits $_ on whitespace by default

# The URL is the first whitespace-separated element.
my $url = $elems[0];

# Handle foo.example.com links and translate them to example.com
# with the rest of the URL intact (if present). Ignore warnings...
if ($url =~ m#^http://adf\.ly(/.*)?#i) {

    $url = substr $url, 22;

    print "$url\n";

}


else {

    # Unmodified URL
    print "$url\n";

}

}

回答1:


This looks like an overly complicated solution for the stated purpose. You can get a more effective result by denying access based on a dstdomain acl

e.g. acl deny_ads dstdomain .adf.ly http_access deny deny_ads

This will prevent this squid's clients from accessing any urls in any subdomain of adf.ly. It's synchronous, requires no DNS lookups so it's also very fast.



来源:https://stackoverflow.com/questions/27492825/squid-url-rewrite-program

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