Section – Rewrite Response Body (HTML only)

Section - Rewrite Response Body (HTML only)

In addition to rewriting HTTP header fields Airlock Gateway also provides a powerful HTML content rewriting engine. Rewriting HTML content may be necessary to modify URLs in the HTML content if the application creates absolute or incorrect links because it is not reverse proxy compatible.

For each rule, the following options can be selected:

  • URI (apply rule to linked HTML elements like href, src, etc.)
  • Events (apply rule to JavaScript event strings such as onsubmit, onload, etc.)
  • Embedded (apply rule to <script> and <style> blocks embedded in the HTML page)

Note: The options Events and Embedded apply the rule to text elements that may contain other text than just a URL. To help Airlock Gateway correctly detect URLs within that text, the following syntax should be used. The type specifier ?<URL> right after the opening parenthesis indicates a URL. If URL encryption is enabled, this URL will also be encrypted.

Examples

Purpose

Simple URI rewrite example to fix up absolute image references

URL Pattern

^/images(/.*)?

Option

URL

Replace with

/%ENTRYPATH%/images$1

Example

HTML snippet from back-end: <img src="/images/company.jpg"> After rewriting: <img src="/entryDir/images/company.jpg">

 

 

Purpose

URI rewrite for removing protocol and host name

URL Pattern

^https?://www.mydomain.com(/[^'"]*)$

Option

URL

Replace with

$1

 

 

Purpose

Rewrite embedded location URLs

URL Pattern

((?:^|[\h\v;.])location(?:\.href)?[\h\v]*=[\h\v]*["'])%BACKENDDIR%((?:/[^'"]*)?['"])

Option

Embedded

Replace with

$1%ENTRYDIR%$2

Example

HTML snippet from back-end: <script> if (isIE) document.location.href = '/redirectIE.html'; else window.location ="/redirect.html"; <script> After rewriting: <script> if (isIE) document.location.href = '/entryDir/redirectIE.html'; else window.location ="/entryDir/redirect.html"; <script>

 

 

Purpose

Encrypt window.open URLs inside embedded JavaScript

URL Pattern

(window\.open[\h\v]*\([\h\v]*["'])(?<URL>[^']+)(["'])

Option

Embedded

Replace with

$1$2$3

 

 

Purpose

Encrypt URLs in location.href assignments inside embedded JavaScript

URL Pattern

((?:^|[\h\v;.])location(?:\.href)?[\h\v]*=[\h\v]*["'])(?<URL>[^"']+)(["'])

Option

Embedded

Replace with

$1$2$3

 

 

Purpose

Encrypt URLs in location.replace functions inside embedded JavaScript

URL Pattern

(location\.replace[\v\h]*\([\v\h]*["'])(?<URL>[^"']+)(["'])

Option

Embedded

Replace with

$1$2$3