using Apache and a prg type rewrite map. My map looks like:

$| = 1; # Turn off buffering 
while (<STDIN>) {
    print "someothersite.com";

the rewrite rule declared in httpd.conf is:

RewriteMap app_map prg:/file/path/test.pl
RewriteRule  (\/[\w]+)(\/[^\#\s]+)?$ http://${app_map:$1}$2 [P,L]

And the log files show:

init rewrite engine with requested uri /a/testlink.html
applying pattern '(\/[\w]+)(\/[^\#\s]+)?$' to uri '/a/testlink.html'

It appears like test.pl is never giving control back to apache, when the map is successfully found I expect to see this output in the log file:

map lookup OK: map=app_map key=/a -> val=someothersite.com

Why is my map not returning control back to apache?


I got it working with the following:

##   disable buffered I/O which would lead
##   to deadloops for the Apache server
$| = 1;
##   read URLs one per line from stdin
while (<>) {
    my $line = $_;
    if ($line eq "input_from_apache\n"){
        print "my_desired_output\n";    
        print "\n";

As best I can tell, the newline characters are what I was missing. For anyone trying to debug a RewriteMap script I suggest:

  1. Make sure you have:

    RewriteEngine On

    RewriteLog /var/log/httpd/rewrite.log

    RewriteLogLevel 9

    in your httpd.conf so you can see what mod_rewrite is doing

  2. Write your script, and then start it (i.e. ./my_script.pl) and type in some inputs to make sure you're getting what you expect. That's how I realized that I needed the \n's

| improve this answer | |

Have you tried having your Perl script return the right format? It expects a key/value pair, i.e.:

someval someothersite.com

That may correct your issues. If not, you can try using a txt file to simulate what your Perl script returns, to verify that the RewriteMap is working at all.

| improve this answer | |
  • If the map were a text file, I could see your point. But a prg type map should receive an input, and respond with an output – SooDesuNe Jan 2 '11 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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