2

I'm looking to get the hostname from a URL as it comes through Zeus and I've looked through the documentation on Trafficscript and it seems like the only option is regex. Doe Trafficscript have a method to return url parts?

I'm looking for something kind of like parse_url

The reason I ask is I have the following rule

$url = string.lowercase(http.getPath());
if(string.contains($url, "/simple_protected_url"))
{
  http.redirect("http://mywebsite.com/");
}

The problem is we have our staging and development sites are not on the same domain name(http://mywebsite.com/) so the rule doesn't work nicely. I want to make the rule more generic so it just redirects to the root of whatever website it runs on and need a way to figure out the host to redirect to.

Thank you

ewwhite
  • 197,159
  • 92
  • 443
  • 809
Paul Sheldrake
  • 537
  • 1
  • 6
  • 14

2 Answers2

0

Yes, that is fairly simple in TrafficScript, for example:

$headerHost = http.getHostHeader();

if( $headerHost == "notwhatiexpected.com") {
   # do something

}

http.getHostHeader(); extracts the Host header from the current request.
And generally there is http.getHeader() to extract any header from the request.

faker
  • 17,496
  • 2
  • 60
  • 70
0

Check through the Stingray Trafficscript Guide.

I think you may be looking for http.getRawURL() or just http.getHeader( "Host" ) or http.getHostHeader()

Returns the HTTP Host header. This value is lowercased and has the port removed. Any trailing full stop is also removed. For example if the Host header is 'www.Riverbed.com:80' then http.getHostHeader() returns 'www.riverbed.com'.

# Get the unambiguous Host header
$hostheader = http.getHostHeader();
ewwhite
  • 197,159
  • 92
  • 443
  • 809
  • They've disabled deep-linking, but I'd recommend a current version of that doc via https://support.riverbed.com/content/support/software/stingray/traffic-manager.html ;) – faker Apr 14 '14 at 14:37