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 26, 2007
The problem is that you are inserting a header in the HTTP response but that is not sent back as part of the request. If you would like to send the client something in the response and have it persisted and sent back on subsequent requests, you'll have to use a HTTP Cookie. The problem with the Cookie approach is that it will be present at a minimum of the current connection. Then future requests within the same connection will still think they have been redirected, when they actually weren't.
Before you go the cookie route, is there any way you can put logic to not issue the redirect if it's already occurred. How about simply checking whether "zoneId=" is in the URI? If it's there, then assume there has been a redirect.
when HTTP_REQUEST {
if { ! ([HTTP::uri] contains "zoneId=") } {
if { [HTTP::path] contains "/zone/" } {
set zoneid [findstr [HTTP::uri] "zoneId=" 0 "&"]
if { [string length $zoneid] > 0 } {
HTTP::respond 301 Location "http://[HTTP::host][HTTP::path]?$zoneid"
}
}
}
}
Now, it will only process the redirect if it contains "/zone/" and not "zoneId=".
-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