Forum Discussion

Bayan_El_Ameen1's avatar
Bayan_El_Ameen1
Icon for Nimbostratus rankNimbostratus
Oct 30, 2011

cookie insertion issue

Hello everyone,

I have been trying to do an iRule to redirect my traffic to a URL in case it's coming from a mobile device to a certain URL and I need to insert to a cookie once the user is redirected there so I don't have to redirect the user each time and get into an infinite redirection.

I have an issue that the URLs are dynamic and have like a hashing format after page load, so in case I request www.example.com/index.htm once I hit enter I am redirected to www.example.com/hsoo389la!pss something like this.

So, assuming that I need to redirect the users to www.example.com/mobile they will be redirected to the mobile app and then the URL will become something like www.example.com/os8903n9!d... which will recall the VS and the iRule and the redirection will reoccurr what will lead to an infinite redirection and I want to prevent that by using a cookie and that's what I tried but when I check using FF my cookies I don't see my cookie inserted. Note that I am using a tool on FF that let's me sending phone headers and it's working.

the iRule:


when HTTP_RESPONSE {
    if { [class match [HTTP::header User-Agent] contains mobile_devices_list] } {
        if { not [HTTP::cookie exists "mobilecookie"] } {
            HTTP::cookie insert name mobilecookie value 1 path / domain www.example.com
            HTTP::redirect "http://www.example.com./mobile"
        }
    }
}

2 Replies

  • i don't think there is user-agent http header in http response.

     

     

    by the way, why won't you redirection only when request is coming from mobile device (by checking user-agent) to / since next request which is /mobile or /hash_value would not trigger the redirection again?

     

     

    or is there anything i missed?
  • just replace HTTP_RESPONSE with HTTP_REQUEST and your iRule should work (it looks good, according to your requirements).

     

     

    Regards

     

    Kurt Knochner