Squid can be used to rewrite requested URL to another URL. The URL rewrite is done transparently without the browser knowing anything. Below is a very simple example of how to rewrite URL using squid using a Perl script.
/usr/local/bin/squid.rewriter.pl:
#!/usr/bin/perl
use warnings;
use strict;
# "forces a flush right away and after every write or print on the currently selected output channel", see perldoc perlvar
$|=1;
while (<>) {
my @inputs=split / /;
chomp($inputs[0]);
if ($inputs[0] =~ q|http://checkwebcam\.com/main\.css|) {
print 'http://localhost/mystyle.css'."\n";
} else {
print "\n";
}
}
Configure squid to call the rewriter script by adding this line to /etc/squid/squid.conf: [[!format ini """ url_rewrite_program /usr/local/bin/squid.rewriter.pl """]
For every request to http://checkwebcam.com/main.css, squid will not get http://checkwebcam.com/main.css instead squid will get http://localhost/mystyle.css and send the content back to the browser. Other request will be processed as usual.