Forum Discussion
raddboy_74501
Nimbostratus
Dec 17, 2009Yet another URI rewrite
With our company divesting, I've been tasked with identifying incoming remote_addr, then intercepting certain URI content and modifying that URI on the fly.
Example: http://www.abc.com/com/usa/wheretogo
identify the com/usa and change it to com/usanew with any prepended or appended URI content remaining the same.
Result: http://www.abc.com/com/usanew/wheretogo
I'm using a Data Group to identify the affect remote_addr, but not sure how to identify the specific URI content and replace it on the fly.
Kevin
4 Replies
- hoolio
Cirrostratus
Hi Kevin,
You can rewrite the URI with HTTP::uri and the path with HTTP::path. Here is an example:when HTTP_REQUEST { Datagroup check loigic goes here ... Check if path starts with /com/usa/ if {[HTTP::path] starts_with "/com/usa/"}{ Replace /com/usa/ with /com/usanew/ in the path HTTP::path [string map {/com/usa/ /com/usanew/} [HTTP::path]] } }
Aaron - mguned_60772
Nimbostratus
Thanks for the info...adding to the question...
What if you also wanted to add a redirect into the situation?
Example:
redirect http://abc.com to http://xyz.com and also change the path as noted above.
-Thanks! - hoolio
Cirrostratus
You can change HTTP::path to HTTP::redirect. You're supposed to use a fully qualified URL in a redirect, but all browsers support a local one (URI without a protocol or domain name).
Aaron - raddboy_74501
Nimbostratus
Hoolio, well done! Works great.
Kevin
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