Sun Java System Web Server 7.0 Update 3 Administrator's Guide

Setting up URL Redirection

URL redirection allows you to redirect document requests for one HTTP URL to another HTTP URL. Forwarding URLs or redirection is a method for the server to tell a user that a URL has changed (for example, because you have moved files to another directory or server). You can also use redirection to seamlessly send request for a document on one server to a document on another server.

For example, if you forward http://www.sun.com/info/movies to a prefix film.sun.com, the URL http://www.sun.com/info/movies redirects to http://film.sun.com/info/movies.

Sometimes you may want to redirect requests for all the documents in one sub-directory to a specific URL. For example, if you had to remove a directory because it was causing too much traffic, or because the documents were no longer to be served for any reason, you can direct a request for any one the documents to a page explaining why the documents were no longer available. For example, a prefix on /info/movies can be redirected to http://www.sun.com/explain.html.

You can set URL redirection at the virtual server level.

To configure URL redirection, perform the following steps:

  1. Click Configurations tab and select the configuration from the configuration list.

  2. Click Virtual Servers sub tab and select the virtual server from the virtual server list.

  3. Click on Content Handling sub tab and URL Redirects sub tab.

  4. Click on New button to add a new URL redirect rule.

  5. Provide necessary values for fields described in . Click on OK button. You may need to click on Deploy button for the configuration if needed.

The following table describes the parameters required while adding a new URL Redirect rule.

Table 9–1 URL redirect Parameters

Parameter

Description

   
   

Source

URI Prefix — URI from which the requests should be redirected. All HTTP requests to this URI pattern will be redirected to the URL specified by the Target URL.

Condition — Instead of providing a URI prefix as source, you can also use regular expression in the condition text field. For example, if you need to redirect requests to a particular URL if the browser is Mozilla, then type $browser = “Mozilla” in the condition field.

Another valid example is $browser =~ “MSIE”.

The Web Server includes a set of variables predefined by the server, as well as the capability for you to define custom variables. In our example, browser is a pre-defined variable. For a list of available pre-defined variables, see Predefined Variables in Sun Java System Web Server 7.0 Update 3 Administrator’s Configuration File Reference.

You can define custom variables in the server.xml file using the variables element and then refer to those variables from this condition text. 

Administration Console supports only <If> tag with redirect SAF for NameTrans directive with all the variables, expression literals, expression functions and expression operators.

For more information on variables, operators and expression, see the Administrator's Configuration File Reference Guide.

Target URL

URL to which the requests should be redirected. All HTTP requests from the URL specified in the From URL will be redirected to this URL.

URL Type

Fixed. Enabled/Disabled. Fixed URLs are static URLs like a link to an HTML page. Non-Fixed URLs are dynamic URLs with request parameters or URLs with just prefixes.

   


Note –

Using CLI

For adding a new URL redirection rule through CLI, execute the following command.


wadm> create-url-redirect --user=admin --password-file=admin.pwd --host=serverhost 
--port=8989 --no-ssl --config=config1 --vs=config1_vs_1 --uri-prefix=/redirect 
--target-url=http://www.cnet.com

See CLI Reference, create-url-redirect(1).