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...
Andy_Herrman_22
Nimbostratus
Sep 26, 2007Are you always removing everything but the zoneID, or is it possible that you'll get a URL with other parameters that you'll want to keep?
If the only parameter you want is zoneID then you can just check to see if there are any other ones in the request. If theres just the zoneID param then you don't need to do a redirect. To detect this just check to see if the query string contains a '&' character. If it does then there are probably multiple query parameters and you want to redirect. If it doesn't then you're good (assuming the zoneID is there).
Also, I'd suggest doing two string searches for zoneID, not the one that's suggested. The search you have right now will get any query parameter that ends in "zoneID", which isn't what you want. It's possible you'd detect the wrong parameter.
Instead, you can do 2 checks. One to see if the string starts with "zoneID=". That would be the case where zoneID is the first query parameter. The other would search for "&zoneID=", which would be the case when the zoneID isn't the first parameter.
when HTTP_REQUEST {
set zoneID ""
if { [HTTP::query] starts_with "zoneID=" } {
We know the first entry is the correct one, so we don't need to
worry about other params that end in "zoneID"
set zoneID [findstr [HTTP::query] "zoneID=" 7 "&"]
}
else {
set zoneID [findstr [HTTP::query] "&zoneID=" 8 "&"]
}
if { $zoneID == "" } {
log local0. "No zoneID defined!"
}
if { [HTTP::query] contains "&" } {
log local0. "Multiple parameters, need to redirect"
Do your redirect here
}
else {
log local0. "Only zoneID provided, no redirect"
Do whatever you want to do when not redirecting
}
}
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