Forum Discussion
C_D_18583
Nimbostratus
Nov 20, 2006Replacing in the URI ; http -> https and port 80 -> 443
What is the easiest way to rewrite the following string? Replacing in the URI http -> https and port 80 -> 443
Before:
https://testlab-d.tdx.dorion.com/amserver/UI/Login?goto=http%3A%2F%2Ftestlab-d.tdx.dorion.com%3A80%2Fperform%2FLogin.do%3FLANGUAGE%3DEN
After:
https://testlab-d.tdx.dorion.com/amserver/UI/Login?goto=https%3A%2F%2Ftestlab-d.tdx.dorion.com%3A443%2Fperform%2FLogin.do%3FLANGUAGE%3DEN
Thanks in Advance!
18 Replies
- C_D_18583
Nimbostratus
Thanks - C_D_18583
Nimbostratus
schwiddy
I need to be able to replace the http -> https and port 80 -> 443 which is in the URI .( See Example Below ) I also may need to replace the Language from say EN ( english) to FR (French) . I am looking for an elegant way to make relacements in the URI.
Thanks
Before:
https://testlab-d.tdx.dorion.com/amserver/UI/Login?goto=http%3A%2F%2Ftestlab-d.tdx.dorion.com%3A80%2Fperform%2FLogin.do%3FLANGUAGE%3DEN
After:
https://testlab-d.tdx.dorion.com/amserver/UI/Login?goto=https%3A%2F%2Ftestlab-d.tdx.dorion.com%3A443%2Fperform%2FLogin.do%3FLANGUAGE%3DEN - The built-in string map TCL command is probably what you'll want.
Here's an example:when HTTP_REQUEST { set query [HTTP::query] set new_query [string map {goto=http% goto=https% %3A80% %3A443% %3DEN %3DFR} $query] HTTP::query $new_query }
-or- in one line:when HTTP_REQUEST { HTTP::query [string map {goto=http% goto=https% %3A80% %3A443% %3DEN %3DFR} [HTTP::query]] }
The first one is better for debugging...
-Joe - C_D_18583
Nimbostratus
Thanks Joe - Steve_Manuel_11
Nimbostratus
Hi Joe;
Tried the following command and it does not appear to work. HTTP_REQUEST is
https://secureinternal-d.tmi.telus.com/amserver/UI/Login?goto=https%3A%2F%2Fsecureinternal-d.tmi.telus.com%3A443%2Feperformance%2FLogin.do%3FLANGUAGE%3DEN
when HTTP_REQUEST {
if { [HTTP::uri] contains "goto"} {
HTTP::query [string map {goto=http% goto=https% %3A80% %3A443%} [HTTP::query]]
log local0. "http string map is [HTTP::query]"
}
}
ltm log output
Nov 22 08:30:35 tmm tmm[702]: Rule D3_INT1_SECURE_REDIRECT_NEW : http string map is goto=http%3A%2F%2Fsecureinternal-d.tmi.telus.com%3A80%2Feperformance%2FLogin.do%3FLANGUAGE%3DEN - some of our variables are cached in the initial request so after making modifications of them (in your case with the HTTP::query command), if you try to access the value it will still return the original cached value. The value is changed, just not in the accessor variable. Have you verified that you servers are not receiving the correct value either by a log file or tcpdump?
-Joe - Steve_Manuel_11
Nimbostratus
Hi Joe;
Yes confirmed that downstream node (Sun Java Web Server) is receiving incorrect URL
172.23.106.13 - - [22/Nov/2006:15:15:54 -0500] "GET /amserver/UI/Login?goto=http%3A%2F%2Fsecureinternal-d.tmi.telus.com%3A80%2Feperformance%2FLogin.do%3FLANGUAGE%3DEN HTTP/1.1" 200 7771
Steve - hoolio
Cirrostratus
The example worked for me:when RULE_INIT { test the string map replacement set aString "" unset aString log local0. " " set aString "/amserver/UI/Login?goto=http%3A%2F%2Fsecureinternal-d.tmi.telus.com%3A80%2Feperformance%2FLogin.do%3FLANGUAGE%3DEN" log local0. "original: $aString" log local0. "new : [string map {goto=http% goto=https% %3A80% %3A443%} $aString]" } when HTTP_REQUEST { test the actual replacement in the URI if { [HTTP::uri] contains "goto"} { HTTP::query [string map {goto=http% goto=https% %3A80% %3A443%} [HTTP::query]] log local0. "this doesn't get updated: [HTTP::query]" log local0. "this is the actual value that gets set: [string map {goto=http% goto=https% %3A80% %3A443%} [HTTP::query]]" } }
Rule : original: /amserver/UI/Login?goto=http%3A%2F%2Fsecureinternal-d.tmi.telus.com%3A80%2Feperformance%2FLogin.do%3FLANGUAGE%3DEN
Rule : new : /amserver/UI/Login?goto=https%3A%2F%2Fsecureinternal-d.tmi.telus.com%3A443%2Feperformance%2FLogin.do%3FLANGUAGE%3DEN
Rule string_map_test_rule : this doesn't get updated: goto=http%3A%2F%2Fsecureinternal-d.tmi.telus.com%3A80%2Feperformance%2FLogin.do%3FLANGUAGE%3DEN
Rule string_map_test_rule : this is the actual value that gets set: goto=https%3A%2F%2Fsecureinternal-d.tmi.telus.com%3A443%2Feperformance%2FLogin.do%3FLANGUAGE%3DEN
Are you sure you're using string map in the form:
set updated_string [string map {find_this replace_with_this} source_string]
Aaron - Steve_Manuel_11
Nimbostratus
Aaron;
My tests mirror yours however having trouble building the full URI. Do you have a recommendation here? - hoolio
Cirrostratus
If you're setting the query to the updated value using HTTP::query and string map, you shouldn't need to modify the URI.
Can you provide more detail on what you're trying to do and what's not working?
Thanks,
Aaron
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