Windows – Squid with php or perl “url_rewrite_program” on windows

perlPHPsquidwindows

I want to redirect all my http proxy traffic to a perl or php script.

I have a working squid setup, and have this in my squid.conf

url_rewrite_program "c:\\squid\\redirect.pl"

But when I start squid in the console it exists with abnormal program termination and this is in the cache.log:

    2012/03/23 19:26:12| helperOpenServers: Starting 5 'c:\squid\php\redirect.pl' processes
2012/03/23 19:26:12| ipcCreate: CHILD: c:\squid\php\redirect.pl: (8) Exec format error
2012/03/23 19:26:12| ipcCreate: PARENT: OK read test failed
2012/03/23 19:26:13| --> read returned 4

Same happens with the PHP script. The scripts are working fine when I execute directly in the console.

Content of perl script:

#!/usr/bin/env perl
$|=1;
while (<>) {
  $url = m/^([^ ]*)/;
  if ($url !~ /^http:\/\/www\.hostname\.com/) {
    $url =~ s@^http://www\.hostname\.com/(.*)@http://www.hostname.com/\1@;
    print "301:$url\n";
  } else {
    print "$url\n";
  }
}
enter code here

Best Answer

From http://wiki.squid-cache.org/KnowledgeBase/Windows :

Squid doesn't know how to run external helpers based on scripts, like .bat, .cmd, .vbs, .pl, etc. So in squid.conf the interpreter path must be always specified, for example:

url_rewrite_program c:/perl/bin/perl.exe c:/squid/libexec/redir.pl