httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o.@wol.dk (WOL - Odinn Sorensen)
Subject [PATCH] apache_1.3.9-mod_rewrite-hash-patch
Date Sat, 09 Oct 1999 20:04:16 GMT
Hello new-httpd@apache.org.

While investigating ways to do really massive virtual hosting, I needed some
way to introduce hashing of document roots, without the overhead of calling 
external mapping programs.

The following patch to mod_rewrite (against 1.3.9), adds a new internal
mapping function, "hash" and the configuration directive RewriteHashBuckets.

Documentation:

=== cut ===
  RewriteHashBuckets

     Syntax: RewriteHashBuckets number-of-buckets
     Default: 211
     Context: server config, virtual host, directory, .htaccess
     Override: FileInfo
     Status: Extension
     Module: mod_rewrite.c
     Compatibility: patch to Apache 1.3.9

     The RewriteHashBuckets directive sets the hash buckets number for the
     internal hash map function for the current per-server or per-directory
     configuration. The number should be a prime number for optimal hash
     distribution.
=== cut ===

Addition to the section "* Internal Function":

=== cut ===
          + hash:
            Converts the looked up key to a hash value of the key, after
            the key is converted to all lower case. The hash value is the
            result of an "ELF hash" of the key, modulus the value of
            RewriteHashBuckets.
=== cut ===

Example usage:

RewriteEngine On
RewriteHashBuckets 1021
RewriteMap hash int:hash
RewriteRule ^/(.*)$ /vhome/${hash:%{SERVER_NAME}}/%{SERVER_NAME}/$1

A request for "www.odinns.dk/index.html" would translate to:
"/vhome/595/www.odinns.dk/index.html" in this example.

A program to generate the hash number is trivial. A simple one follows the
patch.

Finally here is the patch (I hope it's okay to post it uuencoded):

=== Cut ===
begin 644 apache_1.3.9-mod_rewrite-hash-patch
M*BHJ(&%P86-H95\Q+C,N.2]S<F,O;6]D=6QE<R]S=&%N9&%R9"]M;V1?<F5W
M<FET92UO;&0N8PE3870@3V-T("`Y(#(P.C(U.C0S(#$Y.3D*+2TM(&%P86-H
M95\Q+C,N.2]S<F,O;6]D=6QE<R]S=&%N9&%R9"]M;V1?<F5W<FET92YC"5-A
M="!/8W0@(#D@,C`Z,#(Z,S@@,3DY.0HJ*BHJ*B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](&%P7V%P<&5N
M9%]A<G)A>7,H<"P@;W9E<G)I9&5S+3YR97=R:71E<G5L97,L"B`@("`@("`@
M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@(&)A<V4M
M/G)E=W)I=&5R=6QE<RD["BL@("`@("`@("!A+3YR97=R:71E:&%S:&)U8VME
M=',@/2!O=F5R<FED97,M/G)E=W)I=&5L;V=L979E;"`A/2`P(`HK("`@("`@
M("`@("`@("`@("`@("`@("`@("`@("`@/R!O=F5R<FED97,M/G)E=W)I=&5H
M87-H8G5C:V5T<PHK("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@.B!B
M87-E+3YR97=R:71E:&%S:&)U8VME=',["B`@("`@('T*("`@("`@96QS92![
M"B`@("`@("`@("`O*@HJ*BHJ*BHJ*BHJ*BHJ*BH**BHJ(#(Y,BPR.3<@*BHJ
M*@HM+2T@,CDX+#,P-"`M+2TM"B`@("`@("`@("!A+3YR97=R:71E;6%P<R`@
M("`@/2!O=F5R<FED97,M/G)E=W)I=&5M87!S.PH@("`@("`@("`@82T^<F5W
M<FET96-O;F1S("`@(#T@;W9E<G)I9&5S+3YR97=R:71E8V]N9',["B`@("`@
M("`@("!A+3YR97=R:71E<G5L97,@("`@/2!O=F5R<FED97,M/G)E=W)I=&5R
M=6QE<SL**R`@("`@("`@(&$M/G)E=W)I=&5H87-H8G5C:V5T<R`](&]V97)R
M:61E<RT^<F5W<FET96AA<VAB=6-K971S.PH@("`@("!]"B`@"B`@("`@(')E
M='5R;B`H=F]I9"`J*6$["BHJ*BHJ*BHJ*BHJ*BHJ*@HJ*BH@,S$U+#,R,"`J
M*BHJ"BTM+2`S,C(L,S(X("TM+2T*("`@("`@82T^8F%S975R;"`@("`@("`@
M(#T@3E5,3#L*("`@("`@82T^<F5W<FET96-O;F1S("`@(#T@87!?;6%K95]A
M<G)A>2AP+"`R+"!S:7IE;V8H<F5W<FET96-O;F1?96YT<GDI*3L*("`@("`@
M82T^<F5W<FET97)U;&5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
M(&5N=')I97,@*B\*("`@("`@<V5R=F5R7W)E8R`@("IS97)V97([("`@("`@
M("`@("\J('1H92!C;W)R97-P;VYD:6YG('-E<G9E<B!I;F1I8V%T;W(@*B\*
M*R`@("`@:6YT("`@("`@("`@(')E=W)I=&5H87-H8G5C:V5T<SL@+RH@=&AE
M(%)E=W)I=&5(87-H0G5C:V5T<R`J+PH@('T@<F5W<FET95]S97)V97)?8V]N
M9CL*("`*("`**BHJ*BHJ*BHJ*BHJ*BHJ"BHJ*B`S,3DL,S(T("HJ*BH*+2TM
M(#,R,BPS,C@@+2TM+0H@("`@("!A<G)A>5]H96%D97(@*G)E=W)I=&5R=6QE
M<SL@("`@+RH@=&AE(%)E=W)I=&52=6QE(&5N=')I97,@*B\*("`@("`@8VAA
M<B`@("`@("`@("ID:7)E8W1O<GD[("`@("`@("\J('1H92!D:7)E8W1O<GD@
M=VAE<F4@:70@87!P;&EE<R`J+PH@("`@("!C:&%R("`@("`@("`@*F)A<V5U
M<FP[("`@("`@("`@+RH@=&AE(&)A<V4M55),("!W:&5R92!I="!A<'!L:65S
M("HO"BL@("`@(&EN="`@("`@("`@("!R97=R:71E:&%S:&)U8VME=',[("\J
M('1H92!297=R:71E2&%S:$)U8VME=',@*B\*("!](')E=W)I=&5?<&5R9&ER
M7V-O;F8["B`@"B`@"BHJ*BHJ*BHJ*BHJ*BHJ*@HJ*BH@,SDX+#0P,R`J*BHJ
M"BTM+2`T,#(L-#`X("TM+2T*("`@("`@("`@("`@("`@("`@("`@("`@("`@
M("`@("`@("`@("`@("`@("`@("`@("`@(&-H87(@*G-T<BD["B`@<W1A=&EC
M(&-O;G-T(&-H87(@*F-M9%]R97=R:71E<G5L95]S971F;&%G*'!O;VP@*G`L
M(')E=W)I=&5R=6QE7V5N=')Y("IC9F<L"B`@("`@("`@("`@("`@("`@("`@
M("`@("`@("`@("`@("`@("`@("`@("`@(&-H87(@*FME>2P@8VAA<B`J=F%L
M*3L**R!S=&%T:6,@8V]N<W0@8VAA<B`J8VUD7W)E=W)I=&5H87-H8G5C:V5T
M<RAC;61?<&%R;7,@*F-M9"P@=F]I9"`J9&-O;F8L(&-H87(@*F$Q*3L*("`*
M("`@("`@+RH@:6YI=&EA;&ES871I;VX@*B\*("!S=&%T:6,@=F]I9"!I;FET
M7VUO9'5L92AS97)V97)?<F5C("IS+"!P;V]L("IP*3L**BHJ*BHJ*BHJ*BHJ
M*BHJ"BHJ*B`T-#(L-#0W("HJ*BH*+2TM(#0T-RPT-3,@+2TM+0H@('-T871I
M8R!C:&%R("IR97=R:71E7VUA<&9U;F-?=&]L;W=E<BAR97%U97-T7W)E8R`J
M<BP@8VAA<B`J:V5Y*3L*("!S=&%T:6,@8VAA<B`J<F5W<FET95]M87!F=6YC
M7V5S8V%P92AR97%U97-T7W)E8R`J<BP@8VAA<B`J:V5Y*3L*("!S=&%T:6,@
M8VAA<B`J<F5W<FET95]M87!F=6YC7W5N97-C87!E*')E<75E<W1?<F5C("IR
M+"!C:&%R("IK97DI.PHK('-T871I8R!C:&%R("IR97=R:71E7VUA<&9U;F-?
M:&%S:"AR97%U97-T7W)E8R`J<BP@8VAA<B`J:V5Y*3L*("!S=&%T:6,@8VAA
M<B`J<V5L96-T7W)A;F1O;5]V86QU95]P87)T*')E<75E<W1?<F5C("IR+"!C
M:&%R("IV86QU92D["B`@<W1A=&EC('9O:60@(')E=W)I=&5?<F%N9%]I;FET
M*'9O:60I.PH@('-T871I8R!I;G0@("!R97=R:71E7W)A;F0H:6YT(&PL(&EN
&="!H*3L*
`
end
=== Cut ===

Here is the hash generator program:

=== Cut ===
begin 644 elfhash.c
M+RH@)$ED.B!E;&9H87-H+F,L=B`Q+C(@,3DY.2\Q,"\P.2`Q.3HU-SHR."!O
M<R!%>'`@)"`J+PH*(VEN8VQU9&4@/&-T>7!E+F@^"B-I;F-L=61E(#QS=&1I
M;RYH/@H*:6YT(&UA:6XH:6YT(&%R9V,L(&-O;G-T(&-H87(J*B!A<F=V*2![
M"B`@8V]N<W0@8VAA<BH@:V5Y.PH@(&EN="!B=6-K971S+"!A<F=N(#T@,CL*
M"75N<VEG;F5D(&QO;F<@9RP@:#L*("!I9BAA<F=C(#P@,RD@>R!P=71S*")U
M<V%G93H@96QF:&%S:"`\8G5C:V5T<SX@/&ME>3X@6VME>2`N+EU<;B(I.R!E
M>&ET*#`I.R!]"B`@8G5C:V5T<R`](&%T;VDH87)G=ELQ72D["B`@=VAI;&4H
M87)G;B`\(&%R9V,I('L*("`):"`](#`["B`@"6ME>2`](&%R9W9;87)G;ET[
M"B`@"7=H:6QE("@J:V5Y*2!["B`@"0EH(#T@*&@@/#P@-"D@*R!T;VQO=V5R
M*"IK97DK*RD["B`@"0EG(#T@:"`F(#!X1C`P,#`P,#!,.PH@(`D):68H9RD@
M:"!>/2!G(#X^(#(T.PH@(`D):"`F/2!^9SL*("`)?0H)("!P<FEN=&8H(B5S
M("5L=5QN(BP@87)G=EMA<F=N72P@:"`E(&)U8VME=',I.PH)("!A<F=N*RL[
2"B`@?0H)<F5T=7)N(#`["GT*
`
end
=== Cut ===

-- 
Med venlig hilsen / Best Regards
  Odinn Sørensen (System Developer) / World Online Denmark A/S
  Peter Bangs Vej 26, 2000 Frederiksberg, Denmark
  Tlf. (+45) 38 14 70 00 - Fax (+45) 38 14 70 07

Mime
View raw message