在.htaccess基数转换 [英] number base conversion in .htaccess

查看:98
本文介绍了在.htaccess基数转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算做以下形式的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.

这篇关于在.htaccess基数转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆