Forum Discussion
mod_rewrite equivalent in irule
I got a request to implement below equivalent of Apache mod_rewrite in F5 using irule.
RewriteCond %{REQUEST_URI} ^/Alias/Web/Main$ [NC]
RewriteCond %{REMOTE_ADDR} ^194\.156\.44\.([0-9]|[1-5][0-9]|6[0-3])$ [NC]
RewriteCond %{HTTP_COOKIE} !userLoggedIn=true [NC]
RewriteRule ^(.*)$ http://aliassso-prod [R=301,L]
Below is what I did in iRule. Since we have to ask our customer to test it, would like to understand if this would work. Atleast, I could test the redirection with my source IP and it works.
if { [URI::decode [string tolower [HTTP::uri]]] matches_regex "^/alias/web/main$" } {
if { [IP::addr [IP::client_addr] equals 194.156.44.0/24 ] } {
if { ![HTTP::cookie exists "userLoggedIn=true"] } {
HTTP::respond 301 noserver Location "http://aliassso-prod"
}
}
}
Thanks in advanced.
2 Replies
- nitass
Employee
can you try this?[root@ve10:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { if { [HTTP::uri] equals "/Alias/Web/Main" } { if { [IP::addr [IP::client_addr] equals 194.156.44.0/26] } { if { [HTTP::cookie value userLoggedIn] ne "true" } { HTTP::respond 301 noserver Location "http://aliassso-prod" } } } } } - samigo_81875
Nimbostratus
Worked, thanks :)
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