Thursday, August 31, 2017

apache 2.2 - mod_rewrite map doesn't work




I am trying to build a simple mod_rewrite map to have category names translated into ids like so: ../category/electronics -> category.php?cat=1



The map is placed inside the www folder. The code ignores the map as if it doesn't exist



This is my rewrite code, what is wrong?



edited: path to catmap.txt, now it's working correctly




DocumentRoot "${path}/www"

....
RewriteMap cat2id txt:${path}/www/catmap.txt
RewriteEngine On
RewriteOptions Inherit
RewriteLogLevel 3
RewriteRule ^/beta/category/(.*) /beta/category.php?cat={cat2id:$1}


Answer



The RewriteRule should be:




RewriteRule ^/beta/category/(.*) /beta/category.php?cat=${cat2id:$1}



I created the file /var/www/beta/category.php with the following contents:





And this is what I get:



$ curl 'http://localhost/beta/category/electronics'

Array
(
[cat] => 1
)

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...