Forum Discussion

shlomi_133455's avatar
shlomi_133455
Icon for Nimbostratus rankNimbostratus
Sep 11, 2013

redirect Server side with no header User-Agent

Hello, I would like to create a rule that redirect only requests with no "User-Agent" I have a rule now that redirect Pc browsers and a switch in the rule that redirect mobile agents. I need another option incase the request come from the application side on the server which is not configured with header User-Agent.

 

thanks in advance, Shlomi.

 

2 Replies

  • Something like this:

    when HTTP_REQUEST {
        if ( not ( [HTTP::header exists User-Agent] ) } {
             .. do something here ..
        }
    }
    
  • You might try "" as one of the switch conditions, but I haven't tested that. This should work though:

    when HTTP_REQUEST {
        if ( not ( [HTTP::header exists User-Agent] ) } {
            HTTP::redirect "http://mywebsite/[HTTP::uri]"
        } else {
            switch -glob [string tolower [HTTP::header User-Agent]] {
                "*blackberry*" -
                "*ipad*" -
                "*iphone*" -
                "*ipod*" {
                    return
                }
                default {
                    HTTP::redirect "http://mywebsite/[HTTP::uri]"
                }
            }
        }
    }