InnoTecSol >ICS >ICS Version: 0.7.2425 Documentation >http(x) >http rewrite extension library
ICS Version: 0.7.2425
http rewrite extension library

The http rewrite plug-in provides the means to rewrite/manipulate requests.

The following outlines the steps required to activate and configure the rewrite extension library to perform request manipulation.

In order to activate the http rewrite plug-in the httprewrite extension library must be loaded according to extension library configuration.

The rewrite module must be the last library to be loaded, thus that request manipulations of other modules are processed before the rewrite module is executed

Windows:


<EXTLIBS>
	<LIB>C:\Programs\ics\bin\httprewrite.dll</LIB>
</EXTLIBS>
	

Unix:


<EXTLIBS>
	<LIB>/usr/lib64/ics/libhttprewrite.so</LIB>
</EXTLIBS>
	

<EXTLIBS>
	<LIB>/usr/lib32/ics/libhttprewrite.so</LIB>
</EXTLIBS>
	

The httprewrite configuration is introduced by the httpx:HTTPREWRITE tag, which can be child of the HOST or NODE tag.


<HOST>
   <httpx:HTTPREWRITE>
		<RULESET>
			<COND>
				<MATCH>
				</MATCH>
			</COND>
			<REWRITE />
		</RULESET>
   </httpx:HTTPREWRITE>
</HOST>
	

The RULESET comprises a

  • COND - condition evaulating whether the SET or REWRITE operation should be executed
  • SET - set definition to change request, response Header fields - not implemented yet
  • REWRITE - rewrite rule defining the modifications done to the request.

Multiple RULESETs can be defined.

The httprewrite condition configuration is introduced by the COND tag, which can be child of the RULESET tag.

Multiple COND tags can be specified that are combined by an OR operation.


<HOST>
   <httpx:HTTPREWRITE>
		<RULESET>
			<COND>
				<MATCH VAR="REQUEST_FILENAME" OP="NOT" FUNC="DEXISTS" >
				</MATCH>
			</COND>
			<COND>
				<MATCH VAR="REQUEST_FILENAME" OP="NOT" FUNC="FEXISTS">
				</MATCH>
				
			</COND>
			<REWRITE />
		</RULESET>
   </httpx:HTTPREWRITE>
</HOST>
	

The COND tag can have on or several MATCH tags which define the condition checks.

Mutliple MATCH tags can be specified and comprise an AND operation

MATCH

The MATCH tag comprises the following attributes

  • VAR
  • OP
  • FUNC
  • STRING

The VAR attribute can specify one of the following variables:

  • REQUEST_FILENAME - the evaluated filename requested
  • REQUEST_URL - the request url
  • HTTP_* - a http header variable prefixed with HTTP_

The OP attribute can be one of the following operators

  • NOT - not true
  • EQ - true

The FUNC attribute can be one of the following Functions

  • FEXISTS - returns true if the variable exists as file
  • DEXISTS - returns true if the variable exists as directory
  • EXISTS - returns true if the variable exits as file or directory

The STRING attribute contains a regular expression, which is applied to the content of the VAR variable.

The httprewrite rewrite configuration is introduced by the REWRITE tag and can be child of the RULESET tag.

Multiple REWRITE tags can be specified.


<HOST>
   <httpx:HTTPREWRITE>
		<RULESET>
			<COND>
				...
			</COND>
			<REWRITE REGEX="^(/horde/.*)$" REPLACE="/horde/rampage.php" PROCOPT="BREAK" />
		</RULESET>
   </httpx:HTTPREWRITE>
</HOST>
	
	
	<httpx:HTTPREWRITE>
        <RULESET>
            <COND>
                <MATCH VAR="REQUEST_FILENAME" OP="NOT" FUNC="FEXISTS" />
                <MATCH STRING="^(/docu/iaeapps/.*/default-\S\S.html)$" OP="EQ" VAR="REQUEST_URL" />
            </COND>
            <!-- <COND>
                <MATCH VAR="" OP="" WITH="" />
            </COND> -->
            <!-- <SET REQUEST="" TO="" />
            <SET RESPONSE="" TO="" />
             -->
            <REWRITE REGEX="(/.*)\/.*(/.*)" REPLACE="\1\2" REDIRECT="302" />
        </RULESET>
        <RULESET>
            <COND>
                <MATCH VAR="REQUEST_FILENAME" OP="NOT" FUNC="FEXISTS" />
                <MATCH STRING="^(/docu/iaeapps/.*)$" OP="EQ" VAR="REQUEST_URL" />
				<MATCH STRING="^(/docu/iaeapps/.*/default-\S\S.html)$" OP="NOT" VAR="REQUEST_URL" />
				<MATCH STRING="^(/docu/iaeapps/default-\S\S.html)$" OP="NOT" VAR="REQUEST_URL" />
            </COND>
            <!-- <COND>
                <MATCH VAR="" OP="" WITH="" />
            </COND> -->
            <!-- <SET REQUEST="" TO="" />
            <SET RESPONSE="" TO="" />
             -->
            <REWRITE REGEX="([^/]+)(-.*)$" REPLACE="default\2" />
        </RULESET>
    </httpx:HTTPREWRITE>
	

The REWRITE tag comprises three attributes

  • REGEX
  • REPLACE
  • PROCOPT

The REGEX attribute specifies the regular expression to apply to the URL

The REPLACE attribute specifies the replacement URL

The PROCOPT attribute specifies the processing option to be applied when the regular expression matches. The supported processing options are:

  • STOP - the rewrite processing will be stopped. The rewritten URL will be evaluated regarding the location, but no further rewrite processing will be done.
  • BREAK - the rewrite processing will be interrupted, meaning no further RULESETS will be applied. However the rewritten URL will be passed through the location evaluation and the respective rewrite rules will be processed again.