Forum Discussion
Rewrite and Redirect iRule v11 using Datagroup
We want to replace a specific string to a specific string but keep the whole remaining URI portion. For example, if original URI is https://qa.company.com/wps/portal/company/personal/banking/checking/index.html, We want to change it to https://qa.company.com/personal/banking/checking/index.html with respond with a 301. We also would like to use a datagroup for additional URI matching. Is there a way to accomplish this using the ProxyPass iRule?
I thought about using something like the following, would this be the best approach? How do I append the rest of the URI?
set httpuri [string tolower [HTTP::uri]]
Rewrite/Redirect
If "/wps/portal/company/personal" is found, “/wps/portal/company” will be removed and the URI becomes simply “/personal”
if {$httpuri starts_with "/wps/portal/company/personal"} {
set httpuri [string replace [HTTP::uri] 0 14]
HTTP::respond 301 https://[HTTP::header "host"]$httpuri
return
}
1 Reply
- Brad_Parker
Cirrus
You could try something like this. It works with if /wps/portal/company/personal is the name of the object in the data group and is contained in the path it will be replaced with the value of the datagroup object, /personal.
when HTTP_REQUEST { if { [class match [string tolower [HTTP::path]] contains uri_dg]}{ set matchURI [class match -name [string tolower [HTTP::path] contains uri_dg] set newValue [class match -value [string tolower [HTTP::path] contains uri_dg] set newURI [string map -nocase "$matchURI $newValue" [HTTP::uri]] HTTP::respond 301 noserver Location "https://[HTTP::host]$newURI" } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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