using Apache and a prg type rewrite map. My map looks like:
#!/usr/bin/perl
$| = 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?
Best Answer
I got it working with the following:
As best I can tell, the newline characters are what I was missing. For anyone trying to debug a RewriteMap script I suggest:
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
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