Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

RewriteRule ^(.*)/PRODUCT_1.aspx
RewriteRule ^(.*)/PRODUCT_2.aspx

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:


this works if i try to call for example: i'm redirected... but if i try to call the redirect doesn't work. So, in my .htaccess this rule:

RewriteRule ^(.*)/PRODUCT_1.aspx

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
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.