Forum Discussion
HTTP_REQUEST and HTTP::redirect and HTTP::respond with if condition and source IP
Thanks Kevin Stewart for the response.
I have used your content with little modification to observe the changes. and result of var log is as below.-- Just note... neither redirecting worked nore HTTP::response reflected in browser. Jul 10 16:11:57 tmm info tmm[7008]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Client (176.203.127.247%1701) is requesting: /oncfo2/ Jul 10 16:11:57 tmm info tmm[7008]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Client IP match Jul 10 16:11:57 tmm info tmm[7008]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Catch /oncfo Jul 10 16:13:02 tmm info tmm[7008]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Client (176.203.127.247%1701) is requesting: /abcd/ Jul 10 16:13:02 tmm info tmm[7008]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Client IP match Jul 10 16:13:02 tmm info tmm[7008]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Default condition Jul 10 16:14:53 tmm1 info tmm1[7009]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Client (176.203.127.247%1701) is requesting: /pqrs/* Jul 10 16:14:53 tmm1 info tmm1[7009]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Client IP match Jul 10 16:14:53 tmm1 info tmm1[7009]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Default condition Jul 10 16:15:19 tmm info tmm[7008]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Client (176.203.127.247%1701) is requesting: /oncres2/ Jul 10 16:15:19 tmm info tmm[7008]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Client IP match Jul 10 16:15:19 tmm info tmm[7008]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Catch /oncres/ Jul 10 16:16:24 tmm1 info tmm1[7009]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Client (176.203.127.247%1701) is requesting: /oncfo1/ Jul 10 16:16:24 tmm1 info tmm1[7009]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Client IP match Jul 10 16:16:24 tmm1 info tmm1[7009]: Rule /DMS_Prod/test_i_Rule_ECR_2 : Catch /oncf1/ - redirecting
when HTTP_REQUEST { log local0. "Client ([IP::client_addr]) is requesting: [HTTP::path]"
if { [IP::addr [IP::client_addr] equals 176.203.127.247%1701] } {
log local0. "Client IP match"
switch -glob [string tolower [HTTP::path]] {
"/use1/*" {
log local0. "Catch /use1/ - redirecting"
HTTP::redirect "https://ecr.host.com.qa/use/"
}
"/use2/*" {
log local0. "Catch /use/"
HTTP::respond 200 content "IP is [IP::client_addr] and -use2-" "Content-Type" "text/xml"
}
"/oncfo1/*" {
log local0. "Catch /oncf1/ - redirecting"
HTTP::redirect "https://ecr.host.com.qa/oncfo/"
}
"/oncfo2/*" {
log local0. "Catch /oncfo"
HTTP::respond 200 content "IP is [IP::client_addr] and -oncfo2-" "Content-Type" "text/xml"
}
"/oncres1/*" {
log local0. "Catch /oncres1/ - redirecting"
HTTP::redirect "https://ecr.host.com.qa/oncres/"
}
"/oncres2/*" {
log local0. "Catch /oncres/"
HTTP::respond 200 content "IP is [IP::client_addr] and -oncres2-" "Content-Type" "text/xml"
}
default {
log local0. "Default condition"
HTTP::respond 200 content "IP is [IP::client_addr] and check it" "Content-Type" "text/xml"
}
}
} else {
log local0. "Client IP doesn't match"
HTTP::respond 200 content "IP is [IP::client_addr] and check it" "Content-Type" "text/xml"
}
}
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