HTTP::redirect

Description

Redirects the current HTTP request to the specified URL, or replaces the current response with a redirect to the specified URL. This command sends the redirect response to the client immediately, so you cannot invoke this command multiple times while processing a single HTTP request (or response), nor can you use any other commands that modify response headers or content after you give this command.
This command always sends an HTTP 302 (Temporary Redirect) status code. If you want to send a different code such as 301 (Permanent Redirect) you may invoke HTTP::respond with a suitable status code and Location header, for example:
HTTP::respond 301 Location https://[HTTP::host][HTTP::uri]

This command sends a response to the client telling the client to send a fresh request to the URL you specify. Most web browsers will display the new URL to the user.
In some situations you may just want to change the URL in a request before it reaches the server. The client need not be notified and will not display the change to the user, plus avoiding an extra network round-trip will improve application performance. To change the request (URI) the server sees without redirecting the client you may invoke the HTTP::path or HTTP::uri commands. You may invoke HTTP::header to replace the Host header if necessary:
HTTP::header Host newhost.example.com

This command is equivalent to the BIG-IP 4.X redirect statement.

Syntax

HTTP::redirect <url>

HTTP::redirect <url>

  • Redirects an HTTP request or response to the specified URL.

Examples

when HTTP_RESPONSE {
  if { [HTTP::status] == 404} {
    HTTP::redirect "http://www.example.com/newlocation.html"
  }
}