Forum Discussion
pgermain_71805
Nimbostratus
Aug 05, 2009URI Rewrite Help
We want to take all requests from a particular IP to a particular URI, and add an additional directory to the URI. We do not want to redirect.
For example, if a request from 2.2.2.2 comes in to /SOAPAPI, I want to rewrite the URI to /SOAPAPI/Test
So far, the iRule I created hasn't worked.
when HTTP_REQUEST {
if { ([IP::client_addr] equals "2.2.2.2") and ([HTTP::uri] starts_with "/SOAPAPI") } {
HTTP::uri "/SOAPAPI/Test[string range $uri 8 end]"
}
}
I lifted this example from DevCentral and I didn't get an error when I created the rule.
The F5 sends a reset when I test it and it doesn't pass the traffic to the inside.
If anybody has some working rules that do the same thing or sees something I am doing wrong, please let me know.
7 Replies
Sort By
- L4L7_53191
Nimbostratus
I believe that the reason why you're getting a reset is that you're referencing a variable that was never set: the $uri variable. Try setting that variable firstset uri [HTTP::uri]
- pgermain_71805
Nimbostratus
Thanks Matt, - L4L7_53191
Nimbostratus
Good work! Just as a suggestion, you may consider using string map instead of regsub, as it's way more efficient and CPU friendly. Here's a recent example of its use for a very similar task: http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=60029&view=topic - pgermain_71805
Nimbostratus
That is the very example I lifted it from. I'm not familiar enough with the scripts to take the original scripts (with regsub) and make the changes suggested in the followup posts. - pgermain_71805
Nimbostratus
Also, the suggestion in that post uses a redirect instead of a rewrite. I'll search some more on string map. - L4L7_53191
Nimbostratus
I think something like this may work for you (untested, syntax or otherwise):set newURI [string map {"/SOAPAPI" "/SOAPAPI/test"} [HTTP::uri]]
- pgermain_71805
Nimbostratus
Matt,
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