0

我是 RewriteEngine 的新手,无法找到以下问题的答案。我经营一个电子商务网站,其中包含不断变化的产品 skus 目录。我们的 URL 是动态的。问题是,如果我想让一个动态变量重定向到另一个动态变量怎么办。

例如,我想要:

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

现在去:

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

我怎样才能通过.htaccess 做到这一点?

提前致谢。

4

2 回答 2

0

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.

于 2010-04-19T16:00:09.833 回答
0

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.

于 2010-04-19T16:01:07.873 回答