Setting URL rewrite rules

Top  Previous  Next

When reverse proxying HTTP/S protocols 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 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 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 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 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 for this rewrite rule..

 

Description: The 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 request URI, 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.

 

Content type: The one or more content types, separated by a semicolon, that the rule should apply to. For example, text/html.

 

Replace scope: The scope to apply the rewrite rule to. Options include all entries, first entry, and last entry.

 

Find pattern: The pattern to match when searching HTML content. This field may also make use of variables available when clicking the Add Variable button.

 

Replacement: The replacement for the matched pattern. This field may also make use of variables available when clicking the Add Variable button.

 

Pattern type: The type of pattern the rule should apply to, exact match or regular expression.

 

Ignore subsequent rewrite rules once processed: If checked, subsequent rewrite rules are ignored once processed.

 

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 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.

 

Direction: The direction of the HTTP message. The default value is CLIENT_SERVER.

 

Scope: The scope that should be used when applying rewrite rule. The default value is HEADERS.

 

Content Type: The one or more content types, separated by a semicolon, that the rule should apply to.

 

Replace scope: The scope to apply the rewrite rule to. The default value is all entries.

 

Find pattern: The pattern to match when searching HTML content. The default pattern is ({GATEWAY_OUTER_IP}:{GATEWAY_PORT})|({GATEWAY_OUTER_HOSTNAME}:{GATEWAY_PORT})|(localhost:{GATEWAY_PORT})|({GATEWAY_OUTER_IP})|({GATEWAY_OUTER_HOSTNAME})|(localhost)

 

Replacement: The replacement for the matched pattern. The default replacement is {SERVER_HOSTNAME}.

 

Pattern type: The type of pattern the rule should apply to. The default value is regular expression. The other option is exact match.

 

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.

 

Direction: The direction of the HTTP message. The default value is Client-server.

 

Scope: The scope that should be used when applying rewrite rule. The default value is HEADERS.

 

Content type: The one or more content types, separated by a semicolon, that the rule should apply to.

 

Replace scope: The scope to apply the rewrite rule to. The default value is all entries.

 

Find pattern: The pattern to match when searching HTML content. The default pattern is ({GATEWAY_OUTER_IP}:{GATEWAY_PORT})|({GATEWAY_OUTER_HOSTNAME}:{GATEWAY_PORT})|(localhost:{GATEWAY_PORT})|({GATEWAY_OUTER_IP})|({GATEWAY_OUTER_HOSTNAME})|(localhost)

 

Replacement: The replacement for the matched pattern. The default replacement is {SERVER_IP}:{SERVER_PORT}

 

Pattern type: The type of pattern the rule should apply to. The default value is regular expression. The other option is exact match.

 

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.

 

Direction: The direction of the HTTP message. The default value is server-client.

 

Scope: The scope that should be used when applying rewrite rule. The default value is HEADERS.

 

Content type: The one or more content types, separated by a semicolon, that the rule should apply to.

 

Replace scope: The scope to apply the rewrite rule to. The default value is all entries. Other options include first entry, last entry.

 

Find pattern: The pattern to match when searching HTML content. The default pattern is ({SERVER_IP}:{SERVER_PORT})|({SERVER_HOSTNAME}:{SERVER_PORT})|({SERVER_IP})|({SERVER_HOSTNAME})

 

Replacement: The replacement for the matched pattern. The default replacement is {GATEWAY_OUTER_IP}:{GATEWAY_PORT}

 

Pattern type: The type of pattern the rule should apply to, The default value is regular expression. The other option is exact match.

 

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.

 

Direction: The direction of the HTTP message. The default value is server-client.

 

Scope: The scope that should be used when applying rewrite rule. The default value is content.

 

Content type: The one or more content types, separated by a semicolon, that the rule should apply to.

 

Replace scope: Scope to apply the rewrite rule to. The default value is all entries. Other options include first entry, last entry.

 

Find pattern: The pattern to match when searching HTML content. The default pattern is ({SERVER_IP}:{SERVER_PORT})|({SERVER_HOSTNAME}:{SERVER_PORT})|({SERVER_IP})|({SERVER_HOSTNAME})

 

Replacement: The replacement for the matched pattern. The default replacement is{GATEWAY_OUTER_IP}:{GATEWAY_PORT}

 

Pattern type: The type of pattern the rule should apply to, The default value is regular expression. The other option is exact match.

 

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.

 

Rule #5

 

Name: HTTP to HTTPS

 

Description: Replaces http:// with https:// in server-client headers, particularly useful in proxying HTTPS to HTTP where redirects may be used.

 

Direction: The direction of the HTTP message. The default value is server-client.

 

Scope: The scope that should be used when applying rewrite rule. The default value is headers.

 

Content type: The one or more content types, separated by a semicolon, that the rule should apply to.

 

Replace scope: Scope to apply the rewrite rule to. The default value is all entries.

 

Find pattern: The pattern to match when searching HTML content. The default pattern is http://

 

Replacement: The replacement for the matched pattern. The default replacement is https://

 

Pattern type: The type of pattern the rule should apply to, The default value is exact match.

 

Rule #6

 

Name: HTTPS to HTTP

 

Description: Replaces http:// with https:// in server-client headers, particularly useful in proxying HTTPS to HTTP where redirects may be used.

 

Direction: The direction of the HTTP message. The default value is server-client.

 

Scope: The scope that should be used when applying rewrite rule. The default value is headers.

 

Content type: The one or more content types, separated by a semicolon, that the rule should apply to.

 

Replace scope:  Scope to apply the rewrite rule to. The default value is all entries.

 

Find pattern: The pattern to match when searching HTML content. The default pattern is https://

 

Replacement: The replacement for the matched pattern. The default replacement is http://

 

Pattern type: The type of pattern the rule should apply to, The default value is exact match.

 

Rewrite Rules for 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

 

 

 

 

 

 





Home | Company | Products | Solutions | Purchase | Support | Services | Blog

© 2023 Redwood Software, Inc.