在.htaccess基数转换基数、htaccess

2023-09-02 00:44:38 作者:久伴必碍

我打算做以下形式的URL重定向:

I intend to do a url redirection of the form :

从:

domain.com/A

domain.com/someResourse/id/10

在此重定向的ID的基础上,从 16 更改为 10 。

in this redirection the base of the id is changed from 16 to 10.

我不知道这是可能使用的.htaccess

I wonder if this is possible using .htaccess

推荐答案

您可以使用的 RewriteMap指令与外部程序映射(PRG :)。这是一个相当adavnced使用mod-rewrite和甚至RewriteMap指令。

You could use RewriteMap with the external program mapping (prg:). This is a quite adavnced use of mod-rewrite and even of RewriteMap.

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

和为Perl脚本(或任何其他语言),没有测试

And for the perl script (or any other language), not tested

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

您可能需要测试和扩展程序,你至少需要返回NULL字符串错误的情况下。您可能还需要添加一些的RewriteCond 在调用此重写规则,如果一些其他的URL不应转换。

You may need to test and extend the program, at least you need to return the "NULL" string in case of error. You may need also to add some RewriteCond before calling this rewriteRule if some other url shouldn't be converted.

您可以使用其他语言为基数16至10重写,这里在PHP 的一个例子。

You can use other languages for the base 16 to 10 rewriter, here's an example in PHP.