I Rule Help

Hello all, i am trying to come up with an irule that will help us accomplish the following, a redirect from http to https, and additionally i also need to have a redirect on a url for example https://abc.com/123 being redirected to https://abc.com/123/login.do inorder words i dont want my the client having to type /login.do when they access the site. Here is an attempt on my part my on i my on the right track…thanks in advance…

when {HTTP::request {

if { ([HTTP::host] eq “abc.com”) && (HTTP::uri] eq"/123/" } {

HTTP::redirect "https://abc.com/123/login.do

}

}

Hi Nassahla,

Assuming that you have 2 virtuals (http and https)

Here is an irule for HTTP

when HTTP_REQUEST {
  HTTP::redirect "https://[HTTP::host]/[HTTP::uri]"
 }

For the HTTPS virtual

when HTTP_REQUEST {
   if { ([HTTP::host] eq "abc.com") and ([HTTP::uri] eq "/123") } {
       HTTP::redirect "https://[HTTP::host]/[HTTP::uri]/login.do"
      }
}

Please keep in mind that the HTTPS to HTTPS redirect will work if the SSL is terminated on the F5 and not on the web server itself.

I hope this helps

Bhattman

Hi Nassahla,

Assuming that you have 2 virtuals (http and https)

Here is an irule for HTTP

when HTTP_REQUEST {
  HTTP::redirect "https://[HTTP::host]/[HTTP::uri]"
 }

For the HTTPS virtual

when HTTP_REQUEST {
   if { ([HTTP::host] eq "abc.com") and ([HTTP::uri] eq "/123") } {
       HTTP::redirect "https://[HTTP::host]/[HTTP::uri]/login.do"
      }
}

Please keep in mind that the HTTPS to HTTPS redirect will work if the SSL is terminated on the F5 and not on the web server itself.

I hope this helps

Bhattman

Hi Nassahla,

Assuming that you have 2 virtuals (http and https)

Here is an irule for HTTP

when HTTP_REQUEST {
  HTTP::redirect "https://[HTTP::host]/[HTTP::uri]"
 }

For the HTTPS virtual

when HTTP_REQUEST {
   if { ([HTTP::host] eq "abc.com") and ([HTTP::uri] eq "/123") } {
       HTTP::redirect "https://[HTTP::host]/[HTTP::uri]/login.do"
      }
}

Please keep in mind that the HTTPS to HTTPS redirect will work if the SSL is terminated on the F5 and not on the web server itself.

I hope this helps

Bhattman

Thanks Bhatman, is it imperative to have 2 virtuals one configured for an http and the other for https or can i just have use the one i have already which is configured for https then do the redirect based on that .. ?

Hi Nassahla,

In order for the HTTP to HTTPS redirect to work you would need a virtual that would accept requests on PORT 80.

If you have 2 virtuals you can certainly handle both http to https and HTTPS to HTTPS.

However, you can also do the same thing on a single virtual.

Here is link to that particular irule

http://devcentral.f5.com/wiki/default.aspx/iRules/HttpHttpsSingleVirtualServer.html

Bhattman

Hello all- i try putting the following in an i-rule editor then checking the syntax, it seems to be throwing errors at me what i my missing here ?.. or is it ok to ignore the i-rule editor forcing about the syntax i am getting it on line all 3 lines…

when HTTP_REQUEST {

if{[HTTP::host]eq"xxx.com")and([HTTP::uri] eq"/xxx")

HTTP::redirect “https://[http::host]/[HTTP::uri]/login.do”

I believe you are missing some braces

when HTTP_REQUEST {
   If { match something.... } {
       Do something...
       }
}

I hope this helps

Bhattman

If the rule you’ve pasted above is the actual rule, you’re missing some curly brackets and an open parenthesis. Also watch your cases - iRules are case sensitive (http::host isn’t valid, but HTTP::host is). It should look something like this:

when HTTP_REQUEST {
if { ([HTTP::host] eq "xxx.com") and ([HTTP::uri] eq "/xxx") } {
HTTP::redirect "https://[HTTP::host]/[HTTP::uri]/login.do"
    }
}

I’ve not tested the above rule, but it should go on clean.

-Matt

sweet thanks for the pointers…