Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
    
So simple! I had added the complete path to php.exe, but encapsuled it with quotes. Without the quotes it is working. thnx –  Webjin Apr 3 '12 at 14:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.