Forum Discussion
http redirect based on path and query strings
For example:
If one of the class entries is:
www1.domain.com/abc/xyz.do?aaa&bbb&ccc www2.domain.com/new/path.do?zzz&yyy&xxx
All of the following must match and redirect to the www2 URL:
www1.domain.com/abc/xyz.do?bbb&ccc&aaa
www1.domain.com/abc/xyz.do?aaa&bbb&ccc&ddd
www1.domain.com/abc/xyz.do?aaa&ddd&ccc&bbb
Does anyone have an elegant solution for this?
5 Replies
- hoolio
Cirrostratus
Hi Jim,
You can parse individual query string parameters and their values using URI::query:
http://devcentral.f5.com/wiki/iRules.uri__query.ashx
I'm not sure what the most efficient way to handle the lookups would be though. Maybe you could always order the parameter values in the data group in the same order and then form the string to lookup in the same way.
For example, if you have a query string like:
param2=anothervalue¶m1=avalue¶m3=value3
you would parse the values for param1, param2 and param3, concatenate them and then do a lookup against the data group which has the param values combined in the same way:
set value [class match -value "[URI::query [HTTP::uri] param1]|[URI::query [HTTP::uri] param2]|[URI::query [HTTP::uri] param3]" equals query_string_parameters_dg]
Your data group would have the parameter values concatenated with pipes as well:ltm data-group uri_to_pool_dg { records { anothervalue|avalue|value3 { data match1 } anothervalue2|avalue3|value5 { data match2 } } type string }
Aaron - Ashish_Ram_Tak1
Nimbostratus
Dear Aaron,
We are banking customer and we have decided to create mobile user login for our Internet customers, below is the senireo
1) Initially we have www.example.in in public DNS now when this request comes to our LTM it will redirect to home.example.co.in, now when any mobile user type www.example.in in his mobile browser he will go to home.example.co.in i have assigned an iRule to the VS of home.example.co.in to redirect that traffic to lite.example.co.in and its working fine if the user is mobile user based on his OS other desktop and laptop users will straight away go to home .example.co.in.
2) Now in another case we have given one link in a webpage of lite.example.co.in IF YOU WANT TO GO TO MAIN SITE PLEASE CLICK HERE, when user click on this link (is main==true) query string will be passed and that particular mobile user will have to move to home.example.co.in.
But unfortunately we still haven't fined any solution for this, could you please help me on the 2nd case.
Below is the iRule which we are using for mobile user redirection.
When HTTP_REQUEST {
if{ [string tolower [HTTP::header “User-Agent”]] contains “*iPhone” } {
HTTP::redirect "https://lite.example.co.in"}
}
Could you please help me on this its an very important and high priority case, thank you in advance for your support.
Regards,
Ashish Takawale - hoolio
Cirrostratus
Hi Ashish,
Make sure to set the string you're comparing to lowercase (iPhone -> iphone). Also remove the * from the string as contains logically checks for *iphone* in the example below.when HTTP_REQUEST { if { [string tolower [HTTP::header "User-Agent"]] contains "iphone" } { HTTP::redirect "https://lite.example.co.in" } }
Here are a couple of posts where we discussed options for mobile client redirects (particularly the iRule in the second example):
https://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/86313/showtab/groupforums/Default.aspx86381
https://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/2160890/showtab/groupforums/Default.aspx2236593
Aaron - Ashish_Ram_Tak1
Nimbostratus
Dear Aaron,
Below is the iRule which i am using currently, should i have to do any changes in it.
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::header User-Agent]] {
"*iphone*" -
"*android*" -
"*ipad*" -
"*windows phone*" -
"*windows ce*" -
"*blackberry*" -
"*symbinos*" -
"*symbain os*" -
"*symbian*" -
"*java*" -
"*winowsphone*" -
"*windowsce*" {
HTTP::redirect "https://lite.example.co.in/[HTTP::uri]"
return
}
}
}
- Ashish_Ram_Tak1
Nimbostratus
Dear Aaron,
Waiting for your reply.
Regards,
Ashish
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com