Forum Discussion

OTS02's avatar
OTS02
Icon for Cirrus rankCirrus
Aug 19, 2015

Is it possible to use an LTM Policy for sending 301 redirects?

Am experimenting with Policies. Hoping it is possible to send 301 redirects with a Policy.

 

11 Replies

  • An LTM policy redirect will only send a 302. You'll need an iRule to send a 301.

    when HTTP_REQUEST {
        if { something } {
            HTTP::respond 301 Location "somewhere"
        }
    }
    
  • Thanks Kevin. Maybe in future releases? Sure would be nice to replace my iRule (with ever growing number of vanity redirects) with a Policy, since it does not have as much performance impact.

     

    BTW, how do I get the Policy to do a 302? I monkeyed around with it, but couldn't arrive at the correct combination.

     

  • Hi,

     

    to do a 302, you must configure:

     

    • policy control : forwarding
    • rule action : http-reply redirect
  • Does anyone know if version 12 LTM Policies allow 301 redirects? Or if this feature has been roadmaped for a future release?

     

  • Hi,

    If you want to define redirect from Local traffic policy, you can add a tcl variable in policy rule and add this irule executing the redirect...

     Redirect from Local Traffic Policy
     to use it, create an action
     tcl set variable
       - name : Redirect
       - expression : Redirect URL
    
    when HTTP_REQUEST {
        if {([info exists "Redirect"])} {
            HTTP::respond 301 Location $Redirect
            return
        }
    }
    
  • Your should create only one LTM Policy that will contains only one Rule.

     

    The Variable Redirect will contains the actual url to be redirected.

     

    The iRule will read the variable Redirect and will redirect to that URL

     

    In my case I redirect to HTTPS. You create a Virtual Server, and Assign the Policy and the iRule. Policy is read first and then the iRule will contains a value for the Redirect Variable.

     

  • ltm policy http2httpsredirect_301_pol {
        last-modified 2017-01-19:10:44:32
        requires { http }
        rules {
            http2httpsredirect_301_rule {
                actions {
                    0 {
                        tcl
                        set-variable
                        expression "https://[getfield [HTTP::host] \":\" 1][HTTP::uri]"
                        name Redirect
                    }
                }
                conditions {
                    0 {
                        http-uri
                        port
                        values { 80 }
                    }
                }
            }
        }
        status published
        strategy first-match
    }
    

    then the iRule is like this:

    ltm rule redirect_from_local_traffic_policy_301_irule {
     Redirect from Local Traffic Policy
     to use it, create an action
     tcl set variable
       - name : Redirect
       - expression : Redirect URL
    
    when HTTP_REQUEST {
        if {([info exists "Redirect"])} {
            HTTP::respond 301 Location $Redirect
            return
        }
    }
    }