vADC Docs

HowTo: Redirect HTTP clients

by PaulWallace on ‎06-10-2015 09:32 AM (1,996 Views)

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


Collected Tech Tips: TrafficScript examples