Forum Discussion
Modify one part of URI Path
I need to change one portion of a URI path based on the value of another portion. For example:
http://www.example.com/dir1/dir2/file.ext?arg1=val1&arg2=val2&arg3
If dir2 then change dir1 to dir5.
HTTP::respond 302 Location http://www.example.com/dir5/dir2/file.ext?arg1=val1&arg2=val2&arg3
I can pull out the 2nd part:
set path2 [URI::path [HTTP::uri] 2 2]
I can check it against the list of values in a data-group and supply the new value but I don’t know how to modify only one portion of the URI.
I'm looking for a command like the set command, only rewrite URI:path portion based on an index.
Thanks!
4 Replies
- nitass
Employee
is this applicable?[root@ve10:Active] config b virtual bar list virtual bar { snat automap pool foo destination 172.28.19.79:80 ip protocol 6 rules myrule profiles { http {} tcp {} } } [root@ve10:Active] config b class foo_class list class foo_class { "/dir2/" { "/dir1/ /dir5/" } } [root@ve10:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { if { [class match -- [HTTP::uri] contains foo_class] } { set uri [string map [class match -value [HTTP::uri] contains foo_class] [HTTP::uri]] HTTP::redirect "http://[HTTP::host]$uri" } } } [root@ve10:Active] config curl -I "http://172.28.19.79/dir1/dir2/file.ext?arg1=val1&arg2=val2&arg3" HTTP/1.0 302 Found Location: http://172.28.19.79/dir5/dir2/file.ext?arg1=val1&arg2=val2&arg3 Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve10:Active] config curl -I "http://172.28.19.79/somethingelse/file.ext?arg1=val1&arg2=val2&arg3" HTTP/1.1 404 Not Found Date: Wed, 24 Oct 2012 00:18:48 GMT Server: Apache/2.2.3 (CentOS) Connection: close Content-Type: text/html; charset=iso-8859-1
- Josh_Abaire
Nimbostratus
Sting map! That's exactly what I needed! Thank you. - Josh_Abaire
Nimbostratus
It's a known tmsh bug in v10. I'm not as dumb as I look! - Josh_Abaire
Nimbostratus
Also, FYI nitass. Your solution got me where I needed, but would result in an endless 302 redirect. Since it never changes /dir2/ it will always match and attempt to redirect. You have to match both:
Recent Discussions
Related Content
* 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