.htaccess中的数字基数转换

时间:2011-07-18 11:11:40

标签: apache .htaccess math mod-rewrite base

我打算对表单执行url重定向:

从:

domain.com/A

domain.com/someResourse/id/10

在此重定向中,ID的基数从 16 更改为 10

我想知道这是否可以使用.htaccess

2 个答案:

答案 0 :(得分:4)

您可以将RewriteMap与外部程序映射(prg :)一起使用。这是对mod-rewrite甚至是RewriteMap的广泛使用。

RewriteLock /var/lock/rewritemaplock.lock
RewriteMap base16to10 prg:/somewher/modrewritemapbase16to10.pl
RewriteRule - ${base16to10:%{REQUEST_URI}}

对于perl脚本(或任何其他语言),未经过测试

#!/usr/bin/perl
$| = 1; # Turn off I/O buffering
while ($uri=<STDIN>) {
    sprintf("/someResourse/id/%d",hex($uri)); 
}

您可能需要测试和扩展程序,至少需要在出现错误时返回“NULL”字符串。如果不应该转换其他网址,您可能还需要在调用此rewriteRule之前添加一些 RewriteCond

您可以使用其他语言作为基础16到10的重写器here's an example in PHP

答案 1 :(得分:1)

无法在.htaccess中进行计算。但您可以将请求发送到PHP(或其他一些语言)脚本进行计算,然后使用标头函数进行重定向。

相关问题