Forum Discussion
Chuchuchui_1605
Nimbostratus
Jun 19, 2010HTTP_REQUEST redirect newbie
I am trying to figure out how to do this redirect with an HTTP_REQUEST and I am confused. I am trying take this https://www.xxx.yyy.com/v1234/login.aspx?id=9999999-99 and redirect it to https://www.xxx.yyy.com/default.aspx?id=9999999-99. I want to take the parameter after the = and put that part into a new url.
3 Replies
- hoolio
Cirrostratus
Can you try something this:when HTTP_REQUEST { Check if some case is true if {[HTTP::uri] starts_with "/v1234"}{ Remove /v1234 from the URI and redirect the client HTTP::redirect "https://[HTTP::host][string map {/v1234 ""} [HTTP::uri]]" } }
Aaron - The_Bhattman
Nimbostratus
or you can do the followingwhen HTTP_REQUEST { Checks to see if the http request starts with a specific URI if {[HTTP::uri] starts_with "/v1234"}{ Takes the information after ID= and uses that in the redirect HTTP::redirect "https://[HTTP::host]/default.aspx?id=[substr [HTTP::query] 3 0]" } }
I hope this helps
Bhattman - Michael_Yates
Nimbostratus
I think it would be a little bit easier to read and maintain by removing the need for the substr.
Temporary Redirect:when HTTP_REQUEST { if {[HTTP::uri] starts_with "/v1234" } { HTTP::redirect is a 302 Temporary Redirect HTTP::redirect "https://[HTTP::host]/default.aspx?[HTTP::query]" } }
Permanent Redirect:when HTTP_REQUEST { if {[HTTP::uri] starts_with "/v1234" } { HTTP::redirect is a 302 Temporary Redirect HTTP::respond 301 Location "https://[HTTP::host]/default.aspx?[HTTP::query]" } }
From your example: https://www.xxx.yyy.com/default.aspx?id=9999999-99
HTTP::host Value: www.xxx.yyy.com
HTTP::path Value: default.aspx
HTTP::query Value: id=9999999-99
The HTTP::path goes upto the ? of the query string, but does not include it.
The HTTP::query starts up after the ?, but doesn't include it either, so you must manually ad it to your HTTP::path.
What Bhattman provide will work, but it is actually writing out the default.aspx?id= and the [substr [HTTP::query] 3 0] is deleting the id= and then writing out the HTTP::query value.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
