Forum Discussion
Dayton_Gray_103
Nimbostratus
Sep 20, 2007Change URI parameters with a 301 redirect
I am looking to change a URI to remove certain query string parameters and redirect with a 301.
Example:
Incoming URI
www.example.com/example.jsp?zoneId=624906&zz=2255956&parentPage=exa...
Sep 20, 2007
iRules has a helper function that will do exactly what you want. The findstr command searches a string for a substring and returns that substring up to a terminating character.
This should do it for you:
when HTTP_REQUEST {
set zoneid [findstr [HTTP::uri] "zoneId=" 0 "&"]
if { [string length $zoneid] > 0 } {
HTTP::redirect "http://[HTTP::host][HTTP::path]?$zoneid"
}
}
The findstr command above looks in the HTTP::uri value for the string "zoneId=" and will return that string including all trailing characters after that string until it hits the termination character of "&" or the end of string. So this sould return "zoneId=624906" for you above example URIs. Then the HTTP::redirect command is issued on a newly built URI with the original path "/example.jsp" appended with a "?" and the found "zoneId=624906"
Keep in mind that this example is not case-sensitive so URIs with "ZONEID=..." will not match. If you want to match for all case examples of "zoneid=", then you with have to do a "string tolower" on the HTTP::uri before the test and only test for a lower case character.
Also, keep in mind that a redirect will only occur for URI's that have the "zoneId=" query string argument in them.
Hope this helps...
-Joe
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