Forum Discussion

Chris_Olson's avatar
Chris_Olson
Icon for Nimbostratus rankNimbostratus
May 06, 2020

URL irule or policy for 308 redirect

I am trying to set up a simple URL redirect rule. I have had no success with irules and partial success using a policy. 

The policy works well except it does not pass all parameters so some things don't work. The host changes but the uri must be preserved.

 

"A client that sees a 308 redirect MUST do the exact same request on the target location. If the request was a POST and and had a body, then the client must do a POST request with a body on the new location."

 

That said, I specified "Match all traffic" as the condition. However, that did not work.

 

ltm policy URL_Redirect {

  controls { forwarding }

  last-modified 2020-05-04:15:37:49

  requires { http }

  rules {

    Redirect_hotfix_example.com {

      actions {

        0 {

          http-reply

          redirect

          location https://hotfix.example.com

        }

      }

    }

  }

  status published

  strategy first-match

}

 

 

 

I've searched for options on redirects including the 308 redirect, using irules and don't get anything. I tried a couple of irules and they are failing. As noted, the host changes but the URI must be preserved. 

 

 

ltm rule redirect_to_hotfix {

  when HTTP_REQUEST {

 

  # Send 308 redirect to https with host altered and URI preserved

  HTTP::respond 308 Location "https//hotfix.example.com[HTTP::uri]"

 }

}

 This returned an endless string in the browser to:

 

https://hotfix.csstars.com/other/https//hotfix.example.com/other/https//hotfix.example.com/other/https//hotfix.example.com/other/https//hotfix.example.com/other/https//hotfix.example.com/other/https//hotfix.example.com/other/.....etc.

 

A more simple rule did not do anything:

 

ltm rule rule_csstars_redirect {

  when HTTP_REQUEST {

  if { [HTTP::host] equals "https://hotfix.example.com" }

     { HTTP::respond 308 Location "https://hotfix.newdomain.com" }

}

 

Any ideas?

 

1 Reply

  • Can you plz add the log inside the irule to check the URI part.

    i.e

    when HTTP_REQUEST {
    	log local0. "requested URI: [HTTP::uri]"
    	if { [HTTP::host] equals "hotfix.example.com" } {
    		HTTP::respond 308 Location https://hotfix.newdomain.com[HTTP::uri]"
    	}
    }

    Thanks