0

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.

CalfCrusher
  • 105
  • 8

1 Answers1

2

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 :-)

Kamil Šrot
  • 333
  • 1
  • 3
  • 10
  • 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 ! – CalfCrusher Oct 31 '12 at 10:09