Using $path to Rewrite Paths in JavaScript Methods or Variables

You can use the $path token to rewrite paths on a path-based multi-homing service that has the Remove Path on Fill option enabled. This token is useful for web applications that require a dedicated web server and are therefore installed in the root directory of the web server. If you protect this type of application with Access Manager using a path-based multi-homing service, your clients access the application with a URL that contains a /path value. The proxy service uses the path to determine which web server a request is sent to, and the path must be removed from the URL before sending the request to the web server.

The application responds to the requests. If it uses JavaScript methods or variables to generate paths to resources, these paths are sent to client without prepending the path for the proxy service. When the client tries to access the resource specified by the web server path, the proxy service cannot locate the resource because the multi-homing path is missing. The figure below illustrates this flow with the rewriter adding the multi-homing path in the reply.

Figure 2-14 Rewriting with a Multi-homing Path

To ensure that all paths generated by JavaScript are rewritten, you must search the web pages of the application. You can then either list all the JavaScript methods and variables in the Additional Names to Search for URL Strings to Rewrite with Host Name section of the rewriter profile, or you can use the $path token in the Additional Strings to Replace section. The $path token reduces the number of JavaScript methods and variables that you otherwise need to list individually.

To use the $path token, you add a search string and a replace string that uses the token. For example, if the /prices/pricelist.html page is generated by JavaScript and the multi-homing path for the proxy service is /inner, you would specify the following strings:

Search String

Replacement String

/prices

$path/prices

This configuration allows the following paths to be rewritten before the web server sends the information to the browser.

Web Server String

Rewritten String for the Browser

/prices/pricelist.html

/inner/prices/pricelist.html

/prices

/inner/prices

This token can cause strings that should not be changed to be rewritten. If you enable Rewrite Inbound Query String Data, Rewrite Inbound Post Data, and Rewrite Inbound Header, the rewriter checks these strings and ensures that they contain the information the web server expects. For example, when these options are enabled, the following paths and domain names are rewritten when found in query strings, Post Data, Call-Back, Destination, If, Notification-Type, or Referer headers.

Browser String

Rewritten String for the Web Server

/inner/prices/pricelist.html

/prices/pricelist.html

/inner/prices

/prices

example.com/inner/prices

inner.com/prices