views:

33

answers:

2

I am new to the RewriteEngine and have not been able to find an answer to the following issue. I run an ecommerce site with an ever changing catalog of product skus. Our URLs are dynamic. The question is, what if I want to have a dynamic variable redirect to a different dynamic variable.

For instance, I want:

http://www.mydomain.com/product.jhtm?id=12345

to now go to:

www.mydomain.com/product.jhtm?id=78910

How can I do this through the .htaccess?

Thanks in advance.

A: 

You will need to use the External Rewriting Program feature of the RewriteMap directive. Effectively, you write an application in whatever language you want (as long as you make it executable), that reads in the original ID on STDIN, and then outputs the new one on STDOUT. You can then reference that application in your RewriteRules.

It may be easier to implement this kind of logic at your application layer, rather than in a .htaccess file, especially since the External Rewriting Program has to be running continously, rather than being called for each new rewrite.

Kazar
A: 

You'll need to use RewriteMap with a map type of prg in order to have a script look up the original ID and return the new one. Don't forget that the query string can only be broken apart in RewriteCond.

Ignacio Vazquez-Abrams