开发者

number base conversion in .htaccess

开发者 https://www.devze.com 2023-03-20 20:32 出处:网络
I intend to do a url redirection of the form : from: domain.com/A into domain.com/someReso开发者_高级运维urse/id/10

I intend to do a url redirection of the form :

from:

domain.com/A

into

domain.com/someReso开发者_高级运维urse/id/10

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

I wonder if this is possible using .htaccess


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}}

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)); 
}

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.

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


It's not possible to do calculations in .htaccess. but you could send the request to a PHP (or some other languages) script where you do the calculation then use the header function to do the redirect.

0

精彩评论

暂无评论...
验证码 换一张
取 消