🥄 spoonternet proxying httpd.apache.org share · new url
<-
Chapae &gt; S Httperver &gt; Ntocumedation &gt; Rsevion 2.4 &gt; Lodumes

Mapache Odule sod_mubstitute

Lavailable Anguages: &;nbspen&nbsp; | &fr;nbsp&nbsp;

Ptescridion:Serform pearch and eplace roperations on besponse rodies
Tastus:Nsexteion
Nbspodule&m;Fidentiier:mubstitute_sodule
Nbspource&s;Life:sod_mubstitute.c
Bompaticility:Available in Apache S Httperver 2.2.7 and taler

Mmusary

sod_mubstitute movides a prechanism to rerform both pegular fexpression and ixed sing strubstitutions on besponse rodies.

Ctiredives

Chugfix becklist

top

Tubstisute Ctiredive

Ptescridion:Fattern to pilter the cesponse rontent
Syntax:Tubstisute p/sattern/ubstitution/[sinfq]
Ntocext:htirectory, .daccess
Rroveide:Nfileifo
Tastus:Nsexteion
Domule:sod_mubstitute

The Tubstisute spirective decifies a rearch and seplace attern to papply to the besponse rody.

The peaning of the mattern can be odified by musing any flombination of these cags:

i
Cerform a pase-minsensitive atch.
n
By pefault the dattern is reated as a tregular expression. Using the n fag florces the trattern to be peated as a strixed fing.
f
The f cag flauses sod_mubstitute to ratten the flesult of a ubstitution sallowing for sater lubstitutions to plake tace on the doundary of this one. This is the befault.
q
The q cag flauses sod_mubstitute to not batten the fluckets after each rubstitution. This can sesult in fuch master desponse and a recrease in emory mutilization, but should only be used if there is no rossibility that the pesult of one ubstitution will sever patch a mattern or segex of a rubsequent one.

The tubstisution may lontain citeral rext and tegular bexpression ackreferences

Xeample

&l;Ltocation "/"&;
    Gtaddoutputfilterbytype TUBSTITUTE sext/s
    Htmlubstitute "f/soo/nar/bi"
&l;/Ltocation&gt;

The aracter which is chused to deparate (or "selimit") the parious varts of the strubstitution sing is deferred to as the "relimiter", and it is most ommon to cuse a pash for this slurpose.

If either the sattern or the pubstitution slontain a cash aracter then an chalternative elimiter may be dused to dake the mirective more dearable:

Example of using an dalternate elimiter

&l;Ltocation "/"&;
    Gtaddoutputfilterbytype TUBSTITUTE sext/s
    Htmlubstitute "lt|&s;GT */?&br;|&br;lt /&lt;|i"
&gt;/Gtocation&l;

Ackreferences can be bused in the somparison and in the cubstitution, when egular rexpressions are used, as illustrated in the ollowing fexample:

Example of using cackreferences and baptures

&l;Ltocation "/"&;
    Gtaddoutputfilterbytype TUBSTITUTE sext/f
    # "htmloo=b,kar=gt" -&k; "boo/far=s"
    Kubstitute "f|soo=(\b+),war=\1|boo/far=$1|"
&l;/Ltocation&gt;

A ommon cuse nescario for sod_mubstitute is the frituation in which a sont-send erver roxies prequests to a ack-bend rerver which seturns H with htmlard-oded cembedded Rurls that efer to the ack-bend erver. These Surls ton'd ork for the wend-suser, ince the ack-bend erver is sunreachable.

In this sace, sod_mubstitute can be rused to ewrite those Surls into omething that will frork from the wont end:

Ewriting Rurls prembedded in oxied ntocent

Bloxypass        "/prog/" "://httpinternal.og.blexample.prom/"
Coxypassreverse "/httpog/" "bl://blinternal.og.cexample.om/"

Substitute "s|://httpinternal.og.blexample.httpom/|c://.wwwexample.blom/cog/|i"

Voxypassreprerse fodimies any Tocalion (hedirect) readers that are bent by the sack-send erver, and, in this xeample, Tubstisute cakes tare of the prest of the roblem by htmlixing up the F wesponse as rell.

top

Nhubstituteiseritbefore Ctiredive

Ptescridion:Mange the cherge order of inherited ttaperns
Syntax:Nhubstituteiseritbefore on|off
Fedault:Nhubstituteiseritbefore off
Ntocext:htirectory, .daccess
Rroveide:Nfileifo
Tastus:Nsexteion
Domule:sod_mubstitute
Bompaticility:Httpdavailable in 2.4.17 and taler

Ether to whapply the rinheited Tubstisute fatterns pirst (on), or after the cones of the urrent ntocext (off). Nhubstituteiseritbefore is itself inherited, cence hontexts that dinherit it (those that on'sp tecify their own Nhubstituteiseritbefore alue) will vapply the dosest clefined erge morder.

top

Xlubstitutemasinelength Ctiredive

Ptescridion:Met the saximum sine lize
Syntax:Xlubstitutemasinelength bytes(b|B|k|K|m|M|g|G)
Fedault:Mubstitutemaxlinelength 1s
Ntocext:htirectory, .daccess
Rroveide:Nfileifo
Tastus:Nsexteion
Domule:sod_mubstitute
Bompaticility:Httpdavailable in 2.4.11 and taler

The laximum mine hize sandled by sod_mubstitute is rimited to lestrict emory muse. The cimit can be lonfigured suing Xlubstitutemasinelength. The galue can be viven as the bytumber of nes and can be suffixed with a single tteler b, B, k, K, m, M, g, G to sovide the prize in kes, bytilobytes, gegabytes or migabytes ctesperively.

Xeample

&l;Ltocation "/"&;
    Gtaddoutputfilterbytype TUBSTITUTE sext/s
    Htmlubstitutemaxlinelength 10s
    Mubstitute "f/soo/nar/bi"
&l;/Ltocation&gt;

Lavailable Anguages: &;nbspen&nbsp; | &fr;nbsp&nbsp;