Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

in my .htaccess i've tons of directives, with same syntax:

RewriteRule ^(.*)/PRODUCT_1.aspx http://www.site.com/product.php?id_product=2891
RewriteRule ^(.*)/PRODUCT_2.aspx http://www.site.com/product.php?id_product=2896

and everything works. Now, i created a RewriteMap in my because i need to increase velocity (20.000 redirect 301 in htaccess no good), so:

RewriteEngine On
RewriteMap redirects dbm=db:/var/www/html/presta152/prestashop/redirects.db
RewriteCond ${redirects:$1} !=""
RewriteRule ^(.*)$ ${redirects:$1} [redirect=permanent,last]

and my redirects.db is created by redirects.txt, that contains:

/PRODUCT_1.aspx http://www.site.com/product.php?id_product=2891
/PRODUCT_2.aspx http://www.site.com/product.php?id_product=2896

this works if i try to call for example: www.site.com/PRODUCT_1.aspx i'm redirected... but if i try to call www.site.com/everythingpossibileinside/PRODUCT_1.aspx the redirect doesn't work. So, in my .htaccess this rule:

RewriteRule ^(.*)/PRODUCT_1.aspx http://www.site.com/product.php?id_product=2891

works, but in my RewriteMap no. I think i must change this directive:

RewriteRule ^(.*)$ ${redirects:$1} [redirect=permanent,last]

i tried, but unsuccessful. Thanks to all.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You need to modify the RewriteRule like this:

RewriteRule (/[^/]*)$ ${redirects:$1} [redirect=permanent,last]

The regexp (/[^/]*)$ will match the "filename" from the whole URI with preceding backslash... then the RewriteCond will take place and test if there is such translation in your redirects map - if so, the redirect will take place.

Indeed, the order of processing the request in mod_rewrite is a bit counterintuitive :-)

share|improve this answer
you're da man ! works like a charm ! thanks thanks thanks thanks ! also for the explanation ;) i'll study more seriously regexp, i need them more and more often ! –  ienabellamy Oct 31 '12 at 10:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.