Forum Discussion
Need help to redirect all url from http to https
when HTTP_REQUEST { set uri_lower [string tolower [HTTP::uri]] if { $uri_lower starts_with {/test1}} {pool test1_Pool} if { $uri_lower starts_with {/test2} {pool test2_Pool} if { $uri_lower starts_with {/test3}} {pool test3_Pool} if { $uri_lower starts_with {/test4}} {pool test4_Pool} if { $uri_lower starts_with {/test5}} {pool test5_pool} if { $uri_lower starts_with {/test6}} {pool test6-pool} if { $uri_lower starts_with {/test7}} {pool test7-pool} if { $uri_lower starts_with {/test8}} {pool test8_pool} if { $uri_lower starts_with {/test9}} {pool test9_Pool} if { $uri_lower starts_with {/test10}} {pool test10_Pool} }
8 Replies
- StephanManthey
Nacreous
Hi together,
the topic of your question does not match the iRule sample code.
Please clarify.
Regarding the thread´s subject:
There is a built-in iRule to redirect from http to https (/Common/_sys_https_redirect):
when HTTP_REQUEST { HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri] }It takes the original hostname and uri into account and takes care of service port settings.
It just needs to be assigned to your virtual servers listening i.e. on port 80. These servers will need an http-profile and this iRule. Done.
Regarding the iRule code. It can be optimized a bit i.e. as follows:
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/test1*" { pool test1_Pool } "/test2*" { pool test2_Pool } "/test3*" { pool test3_Pool } "/test4*" { pool test4_Pool } default { pool [LB::server pool] } } }Thanks, Stephan
- together_183451
Nimbostratus
Hi Stephan I configured the same and applied it but was unable to access any uri...
- StephanManthey
Nacreous
Hi together, which one did you try? You can make a copy of the F5 built-in irule and add a log statement: log local0. "request: host: <[HTTP::host]>, uri: [HTTP::uri], path: <[HTTP::path]>, query <[HTTP::query]>" Monitor the log file for messages now: tail -f /var/log/ltm Thanks, Stephan - Brad_Parker
Cirrus
Shot in the dark, but ensure you have an HTTP profile attached to the VIP otherwise any HTTP event will not work in your iRule.
- together_183451
Nimbostratus
Also can you please explain me difference between url and uri
- StephanManthey
Nacreous
Hi together, the URL is the resource locator as entered in the browser: i.e. http://www.domain.bit/mypath/myobject?myquery The browser is splitting this information and takes the protocol (http), hostname (www.domain.bit) and uri (/mypath/myobject?myquery) and crafts an HTTP request to be send via port 80 due to http-protocol default setting: GET /mypath/myobject?myquery HTTP/1.1 Host: www.domain.bit The iRule reads the request parameters: [HTTP::host] returns the value of the host-header (www.domain.bit) [HTTP::uri] returns the path and query information separated by questionmark (/mypath/myobject?myquery) [HTTP::path] returns the path related part of uri (/mypath/myobject), leading slash is always included [HTTP::query] returns the query related part of uri (myquery) without the questionmark prefix Please see details on these and other functions in the related Wiki here on DC: https://clouddocs.f5.com/api/irules/HTTP.html Thanks, Stephan
- together_183451
Nimbostratus
Hi Stephan, It is working Thanks for your help
- StephanManthey
Nacreous
Thanks for the feedback! :)
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