Sun Java System Web Server 7.0 Update 1 is enhanced to support regular expressions (also known as Patterns) and request time parameter interpolation in configuration files. In addition, wildcard pattern matching support is extended to server.xml. URL redirecting is implemented as a SAF. The redirect SAF lets you redirect URIs that match a certain prefix. You can specify the prefix using the from parameter and the URL to redirect to using the url or url-prefix parameters. In Sun Java System Web Server Sun Java System Web Server, the from parameter is optional. If from is omitted, all URIs are redirected.
In the obj.conf file, SAF parameters are supported with new <If>, <Elseif> and <Else> tags. These tags contain directives. Using these tags, you can define conditions under which the directives are executed. These tags can also be used to dynamically generate SAF parameters.
Sun Java System Web Server 7.0 Update 1 offers URL rewrite capability that is a super set of Apache HTTP server's mod_rewrite module. Unlike Apache's mod_rewrite function, <If> tag provides the following functionality:
It can manipulate URI, path, header fields and response bodies.
It works at any stage of request processing.
It works with any SAF, including 3rd party plug-ins.
Consider the following directive:
NameTrans fn="redirect" from="/site1" url="http://site1.mycompany.com"
The above directive can be rewritten using regular expression as follows:
<If $uri =~ '^/site1'> NameTrans fn="redirect" url="http://site1.mycompany.com" </If>
In the above snippet, note the usage of regular expression instead of the from parameter. If you need to redirect all requests for /site1/* to http://site1.mycompany.com/*/index.html note this technique:
<If $uri =~ '^/site1/(.*)'> NameTrans fn="redirect" url="http://site1.mycompany.com/$1/index.html" </If>
Here, the <If> tag assigns whatever value matches (.*) to the variable $1. The $1 in the url parameter is dynamically replaced with the value from the original request. That means the above obj.conf snippet will cause a request for /site1/download to be redirected to http://site1.mycompany.com.com/download/index.html.
Combination of <If> and redirect offers some of the flexibility of mod_rewrite. However, unlike mod_rewrite, <If> can be used for things other than redirecting and rewriting URLs. <If> can also be used in conjunction with any SAF, including third party plug-ins.
The above method configures a 302 Moved Temporarily redirect. In Sun Java System Web Server 7.0 Update 1, you can also add a status="301" parameter to indicate that you need a 301 Moved Permanently redirect instead
NameTrans fn="redirect" from="/path" url="http://server.example.com" status="301"