ltm rule command http hostΒΆ

iRule(1)		      BIG-IP TMSH Manual		      iRule(1)



HTTP::host
       Returns the value of the HTTP Host header.

SYNOPSIS
       HTTP::host (HEADER_HOST_VALUE)?

DESCRIPTION
       Returns the value contained in the Host header of an HTTP request. This
       command replaces the BIG-IP 4.X variable http_host.  The Host header
       always contains the requested host name (which may be a Host Domain
       Name string or an IP address), and will also contain the requested
       service port whenever a non-standard port is specified (other than 80
       for HTTP, other than 443 for HTTPS). When present, the non-standard
       port is appended to the requsted name as a numeric string with a colon
       separating the 2 values (just as it would appear in the browser's
       address bar):
	 * Host: host.domain.com:8080

       RFC2616 (section 3.2.3) states that host header evaluation MUST be case
       insensitive. So it is a good practice to set the Host header value to
       lower case before performing comparisons. This can be done using
       [string tolower [HTTP::host]].

       Syntax

       HTTP::host [name]

	    * Returns (or sets in v11.5+) the value of the Host header of an HTTP
	      request.

RETURN VALUE
VALID DURING
       CACHE_REQUEST, HTTP_REQUEST, HTTP_REQUEST_DATA, HTTP_REQUEST_SEND,
       HTTP_PROXY_CONNECT

EXAMPLES
	Both of the following examples redirect all requests containing the
	word "secure" to HTTPS. In this example, if a non-standard port is
	specified, the non-standard port from the Host header value will be
	retained and the resulting redirect will be to the same non-standard
	HTTPS port specifying HTTPS as the scheme:

	when HTTP_REQUEST {
	  if { [HTTP::uri] contains "secure"} {
	    HTTP::redirect "https://[HTTP::host][HTTP::uri]"
	 }
	}

	In this example, if a non-standard port is specified, the non-standard
	port from the Host header value will be removed and the resulting
	redirect will be to the standard HTTPS port specifying HTTPS as the
	scheme:

	when HTTP_REQUEST {
	  if { [HTTP::uri] contains "secure"} {
	    HTTP::redirect "https://[getfield [HTTP::host] : 1][HTTP::uri]"
	  }
	}

	To update the Host header value without redirecting the client to the
	new Host value, you can use HTTP::header replace Host
	   "newhost.example.com". This update will only affect the request to the
	pool member. The client will not see the update unless the web
	application uses the requested host header value to generate response
	headers and/or content.

	when HTTP_REQUEST {

	   # Check if requested host doesn't start with www.example.com
	if {not ([string tolower [HTTP::host]] starts_with "www.example.com")}{

	      # Replace the host header value with newhost.example.com
	      HTTP::header replace Host "newhost.example.com"
	   }
	}

	Here is an another example of the a HTTP::host

	when HTTP_REQUEST {
	  if { [HTTP::host] equals"www.xyz.com"} {
	    HTTP::redirect "http://www.abc.com/index.html"
	  }
	}

HINTS
SEE ALSO
CHANGE LOG
       @BIGIP-9.0.0 --First introduced the command.



BIG-IP				  2017-01-31			      iRule(1)