0

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

<VirtualHost *:80>
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}
</VirtualHost>

1 Answer 1

1

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:

<?php print_r($_GET); ?>

And this is what I get:

$ curl 'http://localhost/beta/category/electronics'
Array
(
    [cat] => 1
)
4
  • Yes, works.. thank you. But I am having trouble placing the map file inside the www folder I need it there so I can auto generate the map file with php. Or that's a bad idea?
    – Yasser
    Jan 7, 2014 at 23:03
  • why not pass 'electronics' directly to the PHP and do the rest in your code? Anyway, you can change the path using txt:/var/www/catmap.txt on the rewritemap.
    – Renan
    Jan 7, 2014 at 23:16
  • I am just testing with the categories, I have over 10,000 products. I really don't know what is the best, I am still trying different ways. Please do advise
    – Yasser
    Jan 7, 2014 at 23:16
  • If you are in doubt about what is best in this case, I would advise to post on stackoverflow.com instead, as it will get the right attention.
    – Renan
    Jan 7, 2014 at 23:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .