Forum Discussion

dmbake88_23490's avatar
dmbake88_23490
Icon for Nimbostratus rankNimbostratus
Jan 11, 2008

http redirect irule

I'm looking to write an irule (unless there is another way to do this with the f5) to redirect an http request coming into a vip. The uri is a little long for the customer and it would be easier on them to use a short uri and then have the f5 add characters or redirect them to a different uri. This probably be done at the server level as well and save me the trouble but I'm still interested on how it is implemented. Below is part of an example I found on this site but I have added more to the uri. I have never configured an irule before so I am unfamiliar with the context. Also, what is the meaning of the '3'? Thanks in advance.

 

 

when HTTP_RESPONSE {

 

if { [HTTP::status] starts_with "3" } {

 

HTTP::header replace Location [string map -nocase {myold.hostname.com mynew.hostname.com} [HTTP::header Host]]

 

}

 

}

3 Replies

  • sorry, the updated uri. as you can see all we are trying to accomplish is adding characters to the uri - i guess this can be considered a redirect.

     

     

    when HTTP_RESPONSE {

     

    if { [HTTP::status] starts_with "3" } {

     

    HTTP::header replace Location [string map -nocase {stringx.stringy.local stringx.stringy.local/xyz/menu4you.maf} [HTTP::header Host]]

     

    }

     

    }
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    (moved to iRules 9.x forum)

     

     

    It's not really clear from your post if you want to redirect @ LTM, or re-write server-generated redirects, or perform URI re-writing. (The sample you've included rewrites server-generated redirects -- the '3' means to catch all 3xx (redirect) server responses. But I suspect that's not really what you need.)

     

     

    It would be helpful if you could detail what you want to change about the request @ LTM, something like this maybe?

     

    My servers are configured to serve content from "/app1root/path/file.ext" and "/app2root/path/file.ext" for content requested for hostnames app1.domain.com & app2.domain.com, but I want my customers to be able to browse to & bookmark "http://app1.domain.com/path/file.ext" instead for each domain.

     

     

    /deb
  • Try this one. We use it to make the URL more "User Friendly".

     

     

    If the URL is http://foo.com/blah/blah2/blah3

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::path] equals "/" } {

     

    HTTP::redirect "/blah/blah2/blah3"

     

    }

     

    }

     

     

    This will enable the user to enter http://foo.com and the F5 will append on the rest of the url to:

     

     

    http://foo.com/blah/blah2/blah3

     

     

    Apply the iRule to the VIP and you should be set.