Forum Discussion
URI substitution
This is what I wrote
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/csn/CI/" } {
set NCI [HTTP::header "FILTER"]
log local0. "$NCI"
HTTP::uri [string map {/csn/CI/ /csn/"$NCI"/} [HTTP::uri]]
log local0. [string map {/csn/CI/ /csn/"$NCI"/} [HTTP::path]]
HTTP::path [string map -nocase {/csn/CI/ /csn/"$NCI"/} [HTTP::path]]
}
}
Problem is that the url https://xyz.com/csn/CI/value1/generic.html is being re-written to https://xyz.com/csn/"$NCI"/value1/generic.html
I want it to be https://xyz.com/csn/IBMCORP/value1/generic.html
So the value for $NCI is not being substituted. However for log.local0. "NCI" actually prints out the right value = IBMCORP
9 Replies
- hoolio
Cirrostratus
Hi,
The curly braces prevent variable expansion. So the string map is probably doing a literal replacement of "$NCI". If you replace the curly braces with double quotes it should work:
HTTP::path [string map -nocase "/csn/CI/ /csn/$NCI/" [HTTP::path]]
Aaron - doc_hack_12696
Nimbostratus
Just tried it. It works! Thank you - greeblesnort
Nimbostratus
sorry to revive an old thread, but this is very similar to my current issue. I'm trying to rewrite an incoming request thusly:
Log output is:when HTTP_REQUEST {set OLDPATH [HTTP::path]log local0.info "got request for $OLDPATH"if {[HTTP::path] starts_with "/dealers"} {HTTP::path [string map -nocase "/dealers/ /used_car_classifieds/dealer/" [HTTP::path]]set NEWPATH [HTTP::path]log local0. "$OLDPATH should've been rewritten to $NEWPATH"}}
Jan 20 15:17:38 local/tmm info tmm[5350]: Rule dvlp_dealer_rewrite : /dealers/IL/Chicago/VOLVO should've been rewritten to /dealers/IL/Chicago/VOLVO
so the rule is firing, but I'm either not doing the string map correctly, or the [HTTP::path] isn't getting updated? - hoolio
Cirrostratus
The results for these HTTP:: commands are cached in the same event and event priority:
HTTP::password
HTTP::username
HTTP::host
HTTP::path
HTTP::query
HTTP::request_num
HTTP::status
HTTP::uri
HTTP::is_keepalive
HTTP::is_redirect
HTTP::request
In v11, this caching was fixed so that if one of the request components was updated the cached value would be updated too. I assume you're testing on v10 so you'll still see the cached value. If you want to verify the rewrite is being done as expected, you can use a later HTTP_REQUEST priority:when HTTP_REQUEST priority 501 { This event runs after the HTTP_REQUEST event with a default priority of 500 log local0. "Updated \[HTTP::path\]: [HTTP::path]" }
Aaron - greeblesnort
Nimbostratus
Running 10.2.3 build 123.0 HF1, so yes, we're still on 10.Regarding priority, I turned up logging trying to troubleshoot this and see this in the logs:
Jan 20 15:12:22 local/tmm debug tmm[5350]: 01220003:7: Virtual dvlp_cfx_vs - Updated rule dvlp_dealer_rewrite when priority 32768000
Is this a different priority or do we have a setting out of wack somewhere? I know I've read that, by default, iRules are priority 500(?), and I don't recall changing it, but this setup is only about 2 weeks old, so we're still in the "getting comfortable with it" phase.
- greeblesnort
Nimbostratus
Running 10.2.3 build 123.0 HF1, so yes, we're still on 10.Regarding priority, I turned up logging trying to troubleshoot this and see this in the logs:
Jan 20 15:12:22 local/tmm debug tmm[5350]: 01220003:7: Virtual dvlp_cfx_vs - Updated rule dvlp_dealer_rewrite when priority 32768000
Is this a different priority or do we have a setting out of wack somewhere? I know I've read that, by default, iRules are priority 500(?), and I don't recall changing it, but this setup is only about 2 weeks old, so we're still in the "getting comfortable with it" phase.
- greeblesnort
Nimbostratus
Running 10.2.3 build 123.0 HF1, so yes, we're still on 10.Regarding priority, I turned up logging trying to troubleshoot this and see this in the logs:
Jan 20 15:12:22 local/tmm debug tmm[5350]: 01220003:7: Virtual dvlp_cfx_vs - Updated rule dvlp_dealer_rewrite when priority 32768000
Is this a different priority or do we have a setting out of wack somewhere? I know I've read that, by default, iRules are priority 500, and I don't recall changing it, but this setup is only about 2 weeks old, so we're still in the "getting comfortable with it" phase.
- greeblesnort
Nimbostratus
woops, double post
- hoolio
Cirrostratus
If you don't specify the priority for an iRule or iRule event it defaults to 500. For your HTTP::path rewrite to work, you don't need to set a custom priority. The rewrite should be working fine as it is. To see the change logged you could add the debug event with a higher priority.
Here's the priority wiki page for some background:
http://devcentral.f5.com/wiki/iRules.priority.ashx
Aaron
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
