Forum Discussion

samigo_81875's avatar
samigo_81875
Icon for Nimbostratus rankNimbostratus
Jul 30, 2013

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

  • 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"
          }
        }
      }
    }
    }