Showing results for 
Search instead for 
Did you mean: 

HowTo: Redirect HTTP clients

The TrafficScript function http.changeSite() makes it easy to redirect clients from one domain to another.  You can also use it to reliably redirect clients from http to https (or https to http), or from one document tree on a website (e.g. /products) to another (e.g /sales).

# Example: Redirect client from to

if( geo.getCountryCode( request.getRemoteIP() ) == "GB" ) {

  http.changeSite( "" );


# Example: Force client to https (assuming this rule is attached to an HTTP virtual server)

http.changeSite( "https://" . http.getHostHeader() );

# Example: move client from one tree to another

$path = http.getPath();

if( string.startsWith( $path, "/products" ) ) http.changeSite( http.getHostHeader(). "/sales" );

For more fine-grained control of HTTP redirects, you can also use the http.redirect() function.

Read more

Version history
Revision #:
1 of 1
Last update:
‎02-25-2013 02:17:AM
Updated by:
Labels (1)

This is what I'm preeping to put in:


$request = http.getRequest();
if( string.contains( http.getheader( "Host" ), "" ) ){
http.changeSite( "https://" . http.getHostHeader() );