Forum Discussion

Tom_90789's avatar
Tom_90789
Icon for Nimbostratus rankNimbostratus
Jul 17, 2009

Change part of HTTP::host based on User Agent

I am trying to change the HTTP:host for a HTTP::redirect based on the UserAgent identified.

 

I am able to make it work using a static host, and changing to a different static host, base on the UserAgent, however, we have several mobile web sites, and the logic is if the User Agent detected is in my list, then modify the HTTP::host to m.domain.com but if it is not a mobile device, then send it to www2.domain.com.

 

 

request to www.domain.com/someuri/goeshere

 

if mobile go to m.domain.com/someuri/goesher

 

if not mobile go to www2.domain.com/someuri/goeshere

 

 

 

 

 

 

This is where I am with it...

 

 

when HTTP_REQUEST {

 

set host [HTTP::host]

 

set ua [string tolower [HTTP::header "User-Agent"]]

 

set hostman [split $host "."]

 

if { [matchclass $ua contains $::useragent_list] } {

 

set hostman [lreplace $hostman 0 0 m]

 

[join $hostman "."]

 

{HTTP::redirect] "http://$hostman[HTTP::uri]"}

 

else {

 

set hostman [lreplace $hostman 0 0 "www2"]

 

[join $hostman "."]

 

[HTTP::redirect] "http://$hostman[HTTP::uri]"}

 

}

 

}