I want to redirect some urls with id = n
to id = n + 1000
(where n is a variable). After searching on the internet I found out that I can do this using a prg type RewriteMap directive.
However, I ran into some trouble getting it to work. The code I am using to test using a custom RewriteMap is included below.
This is my test.pl file that I'm using as the map program:
#!/usr/bin/perl
$| = 1; # Turn off buffering
while 开发者_C百科(<STDIN>) {
print $_;
}
I've defined the RewriteMap in my virtualhost.conf file:
RewriteMap prp prg:/var/www/mydomain1.com/test.pl
And this is the RewriteRule where I'm using my custom map:
RewriteRule ^Pro-id-([0-9]+).html http://mydomain2.um.ac.ir/papers-${prp:$1}.html [L,R=301]
What I expect this code (test.pl) to do is to return the same id, but it returns null. What is the problem?
The stuff you have is just fine, a rewritelog with rewriteloglevel 5 or higher would probably reveal that some other rewrite or config is getting in the way.
Since I just spent a day banging my head against the same problem. It is very likely you are using the map in a context it which it is not defined.
In my case I was using https in my test url and the minute I switched to using http everything started working. In retrospect this should have been completely obvious given the way I had set up the config files.
Make sure you have rewrite engine enabled in your httpd configuration (in either server or virtual host context)
RewriteEngine on
精彩评论