Apache 2.4 never runs RewriteMap program
Since JavaScript cannot access HTTP header Accept-Language
, I decided to pass this information to a custom cookie using .htaccess as follows:
RewriteRule .* - [CO=HTTP-Accept-Language:%{HTTP:Accept-Language}:%{HTTP_HOST}:1:/]
However, I quickly realized that cookies values are not allowed to use some "special" characters, including semicolon, which is used within Accept-Language
header.
Therefore, I decided to use a simple RewriteMap program written in Perl to replace semicolons with underscore characters.
#!/usr/bin/perl
$| = 1;
while (<STDIN>) {
s/;/_/g;
print $_;
}
In my httpd.conf I defined the RewriteMap with
LogLevel trace8
<IfModule rewrite_module>
RewriteEngine on
Mutex default
RewriteMap lc int:tolower
RewriteMap uc int:toupper
RewriteMap escape int:escape
RewriteMap myprg "prg:/etc/httpd/rewrite/myprg.pl"
</IfModule>
and to test these RewriteMap functions, I modified my .htaccess as follows:
RewriteEngine On
RewriteBase /
RewriteRule .* - [CO=Test1:${uc:%{HTTP:Accept-Language}}:%{HTTP_HOST}:1:/]
RewriteRule .* - [CO=Test2:${myprg:%{HTTP:Accept-Language}}:%{HTTP_HOST}:1:/]
Unfortunately, while uc RewriteMap function works fine, the external myprg doesn't.
With LogLevel trace8
in place, I expected some useful information in log file. But all I found about this external script was this:
map lookup OK: map=myprg key=en-US,en;q=0.9 -> val=
No error, just information that val is empty. Based on this finding, I modified my Perl script to include some internal logging:
#!/usr/bin/perl
use Cwd qw(abs_path);
use File::Spec;
use POSIX;
$| = 1;
my (undef, $directory, $filename) = File::Spec->splitpath(abs_path($0));
open my $file, '>>:encoding(UTF-8)', $directory . ($filename =~ s/(?:\.[^.]*)$/.log/r);
print {$file} (strftime "%F %T", localtime time) . "\tRewriteMap script $filename started\n";
close $file;
while (<STDIN>) {
s/;/?/g;
print $_;
}
After each change, I obviously also restarted Apache server by systemctl restart httpd
Then I realized that my Apache 2.4.6 (CentOS) never run the external RewriteMap script myprg.
I spent hours researching a possible problem on my side, but I didn't find anything wrong in my configuration files. What am I doing wrong? Why do I see no error, no warning, despite the script is never called?
do you know?
how many words do you know