问题
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