Setting URL rewrite rules

Top  Previous  Next

When reverse proxying HTTP/S protocols JSCAPE MFT Gateway can optionally automatically rewrites HTTP headers and/or content using rewrite rules that you specify.  For example, you may wish to trap HTTP responses containing the target host/port and replace them with the local host/port of the gateway.  This can be especially important in cases where HTML content returned by HTTP/S service contains both relative and absolute URL references.

 

Managing Rewrite Rules

Setting Rewrite Rules

Pre-Installed Rewrite Rules

Rewrite Rules for JSCAPE MFT Server Integration

 

Relative URL Example

 

<img src"/path/to/file.jpg">

 

Absolute URL Example

 

<img src"http://remotehost:port/path/to/file.jpg">

 

Relative URL references are easily handled by JSCAPE MFT Gateway without the need to perform any URL rewriting.  Absolute URL references however must be rewritten so that HTTP/S requests are sent through JSCAPE MFT Gateway rather than accessed directly by the client browser.

 

Managing URL Rewrite Rules

 

URL rewrite rules can be managed in the Services > HTTP/S > URL Rewrite Rules... section of JSCAPE MFT Gateway Manager.  A list of commonly used rules are provided with the default installation that should meet most user needs.  To add your own custom rules click on the Add button.

 

Figure 25

 

clip025

 

Figure 26

 

clip026

 

Name - A unique name.

 

Description - Description of this rewrite rule.

 

Direction - The direction of the HTTP message.  Valid values are client-server (i.e. HTTP/S request), server-client (i.e. HTTP/S response) or any direction.

 

Scope - The scope that should be used when applying rewrite rule.  Valid values are headers (i.e. HTTP headers), content (i.e.  HTTP/S response content such as web pages) and headers and content.  Please note that the only valid scope for client-server requests (i.e. HTTP/S request) is headers.  For HTTP/S responses, content will only be modified for the following content types: text/html, text/css, text/javascript.

 

Find regexp - Regular expression to match when searching HTML content.  This field may also make use of variables available when clicking the Add Variable button.

 

Replace regexp - Regular expression to replace matching content found when searching HTML content. This field may also make use of variables available when clicking the Add Variable button.

 

Setting URL Rewrite Rules

 

By default URL rewriting is NOT enabled for HTTP/S services.  This means that HTTP/S response content and HTTP/S request/response headers will NOT be modified.  If the HTTP/S response content being served contains absolute URL then you may need to enable URL rewriting. URL rewrite rules for an HTTP/S service may be enabled only when adding a service under the Services node of JSCAPE MFT Gateway Manager.

 

Figure 27

 

clip027

 

1.  Check the Enable URL rewriting option.

2.  Click the Settings... button to define what URL rewrite rules will be used.

 

Figure 28

 

clip028

 

1.  Check the rules you wish to have enabled.

2.  Use the Up and Down buttons to set the order in which URL rewrite rules are processed. Note - Each rewrite rule will operate on the modified content of any previous rewrite rules executed so it is important that rewrite rules be specified in the correct order.

 

Pre-Installed Rewrite Rules

 

There are a number of pre-installed rewrite rules that you can use for your HTTP/S services.  These should meet the majority of needs when reverse proxying HTTP/S services.  Note that while these rewrite rules are pre-installed they are not automatically enabled for HTTP/S services.  It is important that you clearly understand what each rewrite rule is doing, otherwise you may end up with unexpected results.

 

Rule #1

 

Name: Gateway host/port in request headers to server hostname

 

Description: Replaces outer (i.e. public facing) hostname and/or IP and optional port of the gateway with that of target server hostname in HTTP request headers.

 

Find regexp: ({GATEWAY_OUTER_IP}:{GATEWAY_PORT})|({GATEWAY_OUTER_HOSTNAME}:{GATEWAY_PORT})|(localhost:{GATEWAY_PORT})|({GATEWAY_OUTER_IP})|({GATEWAY_OUTER_HOSTNAME})|(localhost)

 

Replace regexp: {SERVER_HOSTNAME}

 

Scope: HEADERS

 

Direction: CLIENT_SERVER

 

Note, this rule should be used on services running on default ports (80,443).   This rule should not be used in combination with Rule #2.

 

Rule #2

 

Name: Gateway host/port in request headers to server IP:port

 

Description: Replaces outer (i.e. public facing) hostname and/or IP and optional port of the gateway with that of target server IP and port in HTTP request headers.

 

Find regexp: ({GATEWAY_OUTER_IP}:{GATEWAY_PORT})|({GATEWAY_OUTER_HOSTNAME}:{GATEWAY_PORT})|(localhost:{GATEWAY_PORT})|({GATEWAY_OUTER_IP})|({GATEWAY_OUTER_HOSTNAME})|(localhost)

 

Replace regexp: {SERVER_IP}:{SERVER_PORT}

 

Scope: HEADERS

 

Direction: CLIENT_SERVER

 

Note, this rule should be used on services running on non-default ports (other than 80,443).  This rule should not be used in combination with Rule #1.

 

Rule #3

 

Name: Server host/port in response headers

 

Description: Replaces hostname and/or IP and optional port of the target server with that of outer (i.e. public facing) IP and port of the gateway in HTTP response headers.

 

Find regexp: ({SERVER_IP}:{SERVER_PORT})|({SERVER_HOSTNAME}:{SERVER_PORT})|({SERVER_IP})|({SERVER_HOSTNAME})

 

Replace regexp: {GATEWAY_OUTER_IP}:{GATEWAY_PORT}

 

Scope: HEADERS

 

Direction: SERVER_CLIENT

 

 

Note, this rule should be used for most services.

 

Rule #4

 

Name: Server host/port in response content

 

Description: Replaces hostname and/or IP and optional port of the target server with that of outer (i.e. public facing) IP and port of the gateway in HTTP response content.

 

Find regexp: ({SERVER_IP}:{SERVER_PORT})|({SERVER_HOSTNAME}:{SERVER_PORT})|({SERVER_IP})|({SERVER_HOSTNAME})

 

Replace regexp: {GATEWAY_OUTER_IP}:{GATEWAY_PORT}

 

Scope: CONTENT

 

Direction: SERVER_CLIENT

 

This rule has the same regular expressions used in Rule #3 but is applied to the content only.  The reason for providing separate rules is that there is noticeable performance improvement for web sites where there is no need for content rewriting.  For maximum performance, this rule should not be used except when needed.

 

 

 

Rewrite Rules for JSCAPE MFT Server Integration

 

For HTTP/S services running on default ports you should use the following Pre-Installed Rewrite Rules.

 

Rule #1, Rule #3, Rule #4

 

For HTTP/S services running on non-default ports you should use the following Pre-Installed Rewrite Rules.

 

Rule #2, Rule #3, Rule #4