Forum Discussion
Piotr_Pozna_ski
Nimbostratus
Apr 24, 2015Best way to rewrite uri to pass path segment as part of query string?
Hello.
I need URI's matching pattern
/prefix// where is of form [a-z]{1,} to be passed to the internal host as / with id as a part of query string id=.
For example:
/prefix/foo/ -> /?id=foo
/prefix/foo/path -> /path?id=foo
/prefix/foo/path? -> /path?id=foo
/prefix/foo/path?p=7 -> /path?p=7&id=foo
What would be the best way to achieve this?
Best regards, Piotr
2 Replies
- Brad_Parker
Cirrus
I haven't tested this yet, but you could try somthing like this.
when HTTP_REQUEST { if {[string tolower [URI::path [HTTP::path] 2 2]] matches_regex "[a-z]{1,}"}{ HTTP::path "/[URI::path [HTTP::path] 3]" if {not ([HTTP::query] equals "")}{ HTTP::query "[HTTP::query]&id=[URI::path [HTTP::path] 2 2]" } else { HTTP::query "id=[URI::path [HTTP::path] 2 2]" } } } - nitass
Employee
e.g.
irule [root@ve11c:Active:In Sync] config tmsh list ltm rule qux ltm rule qux { when HTTP_REQUEST { set uri [HTTP::uri] if { [scan $uri {/%*[^/]/%[^/]%s} id rest] == 2 } { set rest [string trimright $rest "?"] if { $rest contains "?" } { set newuri "${rest}&id=${id}" } else { set newuri "${rest}?id=${id}" } HTTP::uri $newuri } } when HTTP_REQUEST priority 1000 { log local0. "$uri > [HTTP::uri]" } } test [root@ve11c:Active:In Sync] config tail -f /var/log/ltm Apr 24 22:50:02 ve11c info tmm1[5649]: Rule /Common/qux : /prefix/foo/ > /?id=foo Apr 24 22:50:10 ve11c info tmm[5649]: Rule /Common/qux : /prefix/foo/path > /path?id=foo Apr 24 22:50:16 ve11c info tmm1[5649]: Rule /Common/qux : /prefix/foo/path? > /path?id=foo Apr 24 22:50:22 ve11c info tmm[5649]: Rule /Common/qux : /prefix/foo/path?p=7 > /path?p=7&id=foo
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
