Forum Discussion

Richard_77286's avatar
Richard_77286
Icon for Nimbostratus rankNimbostratus
Mar 17, 2017

Help with iRule redirect

I have a request from our dev team to redirect https://www.ourwebsite.com/agentlanguagelocator to https://www.ourwebsite.com/apex_extprd/f?p=119:1. Dev team would like users to use /agentlanguagelo...
  • Jeremy_Church_3's avatar
    Mar 18, 2017

    Hello Richard,

    Based on your iRule, you are not performing a redirect, you are only changing the URI before it is passed to the server. This is completely transparent to the user/browser.

    If your Dev team has requested a redirect, it should probably look closer to this:

     

    when HTTP_REQUEST {
        if {[string tolower [HTTP::uri]] eq "/agentlanguagelocator"} {
            HTTP::respond 302 Location "/apex_extprd/f?p=[URI::encode 119:1]"
        }
    }
    

    Notes

     

    1. Notice the use of HTTP::respond, this is not required as HTTP::redirect will perform the same function. My preference is to use HTTP::respond so the status code is clear at all times and to any readers of the iRule.
    2. The match is only for the URI and it's a case-insensitive exact match. Your requirements may vary.
    3. If the virtual server handles multiple domain names that don't all have this desired behavior, you should include a domain name match as well.
    4. The Location header is /apex_extprd/f?p=119:1 and not the full URL. This is a relative redirect directing the browser to use the same scheme (e.g. http / https) and domain name as the original request, but redirect to a different path. If you need the whole URL, that should be changed.
    5. The value of query parameter p is wrapped with URI::encode. This is because the colon is a reserved URI character and may cause problems if not encoded. You may also directly type 119%3A1 which should be the result of using URI::encode and translates to 119:1.