F5 is upgrading its customer support chat feature on My.F5.com. Chat support will be unavailable from 6am-10am PST on 1/20/26. Refer to K000159584 for details.

Forum Discussion

stupid48's avatar
stupid48
Icon for Altocumulus rankAltocumulus
Apr 05, 2016

iRule redirect issue...

Hi there,

 

I've got a situation where I have a bunch a friendly urls that redirect to unfriendly urls. So, I created an iRule with a switch:

 

when HTTP_REQUEST { switch [string tolower [HTTP::uri]] { "/path1" { HTTP::respond 301 Location "http://www.website.com/unfriendlypath1" } "/path2" { HTTP::respond 301 Location "http://www.website.com/unfriendlypath2" } "/path3" { HTTP::respond 301 Location "http://www.website.com/unfriendlypath3" } } } That's all good and all. Now, I need to add something so that if the user comes in on "http://website.com" (no www), I need to forward them to www.website.com first (i.e. so in their address bar, they see After that happens, if one of the friendly urls match, forward them there. If the uri doesn't match, then just forward them to www.website.com and add whatever uri they had originally. This would address someone coming in on http://website.com/ or http://website.com/otherpath/

 

Thanks for the help...

 

2 Replies

  • You can try this update:

    when HTTP_REQUEST {
        if {[HTTP::host] equals "website.com"} {HTTP::respond 301 Location "http://www.website.com[HTTP::uri]"; return}
        switch [string tolower [HTTP::path]] {
            "/path1" { HTTP::respond 301 Location "/unfriendlypath1" }
            "/path2" { HTTP::respond 301 Location "/unfriendlypath2" }
            "/path3" { HTTP::respond 301 Location "/unfriendlypath3" }
        }
    } 
    

    The first condition is to redirect website.com to www.website.com

    I updated the HTTP respond with only relative URI and not absolute....