Forum Discussion
irule to redirect and amend URI
Hi
I'm trying to write a redirect irule but not having much joy.
The irule firstly needs to identify wireless clients then direct them to poolA
Then it needs to identify internal clients and direct them to poolB, but whilst redirecting to poolB also needs to check if the uri starts with / and ammend to /newuri
All external clients should go to poolA
The default resource on the VS is poolA.
We have a data group called Wireless with all relavant subnets identified.
What I have so far is:
when HTTP_REQUEST {
if { [matchclass [IP::remote_addr] equals $::Wireless] } {
pool PoolA
} elseif { [IP::addr [IP::client_addr]/16 equals 192.168.0.0] } {
pool poolB
}
}
This works well, I also have the following irule:
when HTTP_REQUEST {
if {[HTTP::uri] == "/"}{
HTTP::redirect "/newuri"
}
}
Which will happly replace the uri, what I need is the two combined but URI rewriting only for internal clients only.
- Peter_72728Nimbostratus
I'm assuming you've tried just merging the two and it didn't work...but I'm not sure why it wouldn't. Have you done something like this?
- Peter_72728Nimbostratus
Another option... does the rule have to do a redirect? Would it be okay if it just modified the URI on the way to the pool but didn't update the client's location?
...
elseif { [IP::addr [IP::client_addr]/16 equals 192.168.0.0] } {
}
...
- Colin_Walker_12Historic F5 AccountWhat version are you running? I'm assuming version 9.x since you're still using matchclass. If that's the cast, and it were me, I'd write it something like this:
when CLIENT_ACCEPTED { if { ([matchclass [IP::client_addr] equals $::Wireless]) || !([IP::addr [IP::client_addr] equals 192.168.0.0/16]) } { set pool "poolA" } else { set pool "poolB" } } when HTTP_REQUEST { if { ($pool eq "poolB") && ([HTTP::uri] eq "/")} { HTTP::redirect "/newuri" } else { pool $pool } }
- hooleylistCirrostratusYou could take 192.168.0.0/16 out of the Wireless datagroup and then remove the IP::addr check. Also, if you're on 9.4.4 or higher you can remove the $:: prefix from the datagroup name in the iRule to preserve CMP:
- Colin_Walker_12Historic F5 AccountGood point Aaron, I didn't think about tossing the IP::addr check.
- keefyweefyNimbostratusThat's great, given me plenty to go on, much appreciated.
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