Forum Discussion
Irule to "prepend" directory and retain URI
Hi. i have a requirement for the following:
type somesite.com/anything/anything
then we need to add /something into the URI without a redirect and retain the original client URI request
so the request to the server becomes:
somesite.com/something/anything/anything
it would be nice to see this back on the client browser if possible but cant have a re-direct
when HTTP_REQUEST { HTTP::header replace Host "[HTTP::host]:38080" log local0. "Sending request to server" Log the original path if debug is enabled if {$::uri_mapping_debug}{log local0. "Original path: [HTTP::host][HTTP::uri]"} If the path doesn't already start with the base URI and version, insert it if {[string tolower [HTTP::path]] starts_with "/api/"}{ HTTP::path "/imr-ce-web[HTTP::path]" Log the modified path if debug is enabled if {$::uri_mapping_debug}{log local0. "Modified path: path: [HTTP::host][HTTP::uri]"} } }
4 Replies
so the Irule is not modifying the path for some reason ??
when RULE_INIT {
The base of the URI set ::uri_base "/mystring/"
Enable/disable debug logging to /var/log/ltm set ::uri_mapping_debug 1 }
when HTTP_REQUEST { Log the original path if debug is enabled if {$::uri_mapping_debug}{log local0. "Original path: [HTTP::path]"}
If the path doesn't already start with the base URI and version, insert it if {not ([string tolower [HTTP::path]] starts_with "$::uri_base$::version_string")}{ HTTP::path [string map [list $::uri_base] [HTTP::path]]
Log the modified path if debug is enabled if {$::uri_mapping_debug}{log local0. "Modified path: [string map [list $::uri_base "$::uri_base$::version_string/"] [HTTP::path]]"}} }
Thu Nov 3 19:38:07 GMT 2016 info xxx tmm[14206] Rule /Common/PREPEND-DEV-TEST : Original path: /api/1/claimrefs Thu Nov 3 19:38:07 GMT 2016 info xxx tmm[14206] Rule /Common/PREPEND-DEV-TEST : Modified path: /api/1/claimrefs
So i have cracked it,
when HTTP_REQUEST { HTTP::header replace Host "[HTTP::host]:38080" log local0. "Sending request to server" Log the original path if debug is enabled if {$::uri_mapping_debug}{log local0. "Original path: [HTTP::host][HTTP::uri]"} If the path always starts with /api/ prepend the uri with /something if {[string tolower [HTTP::path]] starts_with "/api/"}{ HTTP::path "/something[HTTP::path]" Log the modified path if debug is enabled if {$::uri_mapping_debug}{log local0. "Modified path: path: [HTTP::host][HTTP::uri]"} } }
when HTTP_REQUEST { HTTP::header replace Host "[HTTP::host]:38080" log local0. "Sending request to server" Log the original path if debug is enabled if {$::uri_mapping_debug}{log local0. "Original path: [HTTP::host][HTTP::uri]"} If the path doesn't already start with the base URI and version, insert it if {[string tolower [HTTP::path]] starts_with "/api/"}{ HTTP::path "/imr-ce-web[HTTP::path]" Log the modified path if debug is enabled if {$::uri_mapping_debug}{log local0. "Modified path: path: [HTTP::host][HTTP::uri]"} } }
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
