TCL实现URI替换脚本仅首次请求生效问题求助
Hey there, let's dig into why your TCL iRule only works on the first request!
The issue here is that your current matching condition only targets requests with an exact URI of /profile. If subsequent requests have a URI that includes parameters (like /profile?id=123) or a trailing slash/subpath (like /profile/settings), the matches_glob "/profile" check won't catch them—hence the script doesn't run for those requests.
Also, notice you defined http_uri and http_host variables but never used them; we can clean those up to simplify the code.
Here's a revised version of your iRule that will handle all requests starting with /profile, regardless of what comes after:
when HTTP_REQUEST { # Match any URI that starts with "/profile" if { [HTTP::uri] starts_with "/profile" } { # Replace all instances of "/profile" with "/account" in the URI HTTP::uri [string map {"/profile" "/account"} [HTTP::uri]] } }
If you specifically want to only replace the exact /profile URI (and not subpaths like /profile/xxx), you can adjust the condition to use a more precise check, like:
when HTTP_REQUEST { set current_uri [HTTP::uri] # Match exact "/profile" or "/profile/" (in case of trailing slash) if { $current_uri eq "/profile" || $current_uri eq "/profile/" } { HTTP::uri "/account" } }
This ensures you're only targeting the exact root profile path, while still accounting for common trailing slash variations.
内容的提问来源于stack exchange,提问作者n santhu

