Forum Discussion
IRULE to take number from URL dynamically and change to port for web server
Need to figure out how to write an IRULE to take input:
https://website.com/login.htmld?rtport=4500 (Can be a range of 4500 to 4599)
and turn it dynamically into:
https://website.com:4500/login.htmld
7 Replies
- Josiah_39459Historic F5 Account
when HTTP_REQUEST { if {[string tolower [HTTP::uri]] starts_with /login.htmld and [HTTP::query [HTTP::uri] rtport] >= 4500 and [HTTP::query [HTTP::uri] rtport] <= 4599 } { HTTP::redirect "https://website.com:[HTTP::query [HTTP::uri] rtport]/login.htmld" } }Should do the trick
- Ciscomadman_204
Nimbostratus
Not sure if the rtport is placed in correct location on redirect. I am new to Irules however...
- nitass_89166
Noctilucent
Not sure if the rtport is placed in correct location on redirect.
e.g.
[root@ve11a:Active:In Sync] config tmsh list ltm rule qux ltm rule qux { when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/login.htmld" and [URI::query [HTTP::uri] rtport] >= 4500 and [URI::query [HTTP::uri] rtport] <= 4599 } { HTTP::redirect "https://website.com:[URI::query [HTTP::uri] rtport]/login.htmld" } } } [root@ve11a:Active:In Sync] config curl -I http://172.28.24.10/login.htmld?rtport=4555 HTTP/1.0 302 Found Location: https://website.com:4555/login.htmld Server: BigIP Connection: Keep-Alive Content-Length: 0- Ciscomadman_204
Nimbostratus
I appreciate this! I love the troubleshooting method you used. I have another question.. If the url changes will the HTTP::uri pickup if it were something new like /test1/login.htmld?
- nitass
Employee
Not sure if the rtport is placed in correct location on redirect.
e.g.
[root@ve11a:Active:In Sync] config tmsh list ltm rule qux ltm rule qux { when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/login.htmld" and [URI::query [HTTP::uri] rtport] >= 4500 and [URI::query [HTTP::uri] rtport] <= 4599 } { HTTP::redirect "https://website.com:[URI::query [HTTP::uri] rtport]/login.htmld" } } } [root@ve11a:Active:In Sync] config curl -I http://172.28.24.10/login.htmld?rtport=4555 HTTP/1.0 302 Found Location: https://website.com:4555/login.htmld Server: BigIP Connection: Keep-Alive Content-Length: 0- Ciscomadman_204
Nimbostratus
I appreciate this! I love the troubleshooting method you used. I have another question.. If the url changes will the HTTP::uri pickup if it were something new like /test1/login.htmld?
- nitass
Employee
If the url changes will the HTTP::uri pickup if it were something new like /test1/login.htmld?
yes, HTTP::uri returns uri of request.
HTTP::uri
https://devcentral.f5.com/wiki/iRules.HTTP__uri.ashx
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