# Need help to redirect all url from http to https

**URL:** <https://community.f5.com/t/need-help-to-redirect-all-url-from-http-to-https/19885>\
**Category:** Technical Forums\
**Created:** [February 14, 2015, 6:59am UTC](https://community.f5.com/t/need-help-to-redirect-all-url-from-http-to-https/19885 "2015-02-14T06:59:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![together\_183451](https://avatars.discourse-cdn.com/v4/letter/t/919ad9/32.png) [@together\_183451](https://community.f5.com/u/together_183451)\
**Post date:** [February 14, 2015, 6:59am UTC](https://community.f5.com/t/need-help-to-redirect-all-url-from-http-to-https/19885/1 "2015-02-14T06:59:33Z")

</div>

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} }

---

<div class="post-metadata">

**Author:** ![StephanManthey](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@StephanManthey](https://community.f5.com/u/StephanManthey)\
**Post date:** [February 14, 2015, 10:30am UTC](https://community.f5.com/t/need-help-to-redirect-all-url-from-http-to-https/19885/2 "2015-02-14T10:30:57Z")

</div>

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):

```tcl
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:

```tcl
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

---

<div class="post-metadata">

**Author:** ![together\_183451](https://avatars.discourse-cdn.com/v4/letter/t/919ad9/32.png) [@together\_183451](https://community.f5.com/u/together_183451)\
**Post date:** [February 14, 2015, 10:59am UTC](https://community.f5.com/t/need-help-to-redirect-all-url-from-http-to-https/19885/3 "2015-02-14T10:59:57Z")

</div>

Hi Stephan I configured the same and applied it but was unable to access any uri…

---

<div class="post-metadata">

**Author:** ![together\_183451](https://avatars.discourse-cdn.com/v4/letter/t/919ad9/32.png) [@together\_183451](https://community.f5.com/u/together_183451)\
**Post date:** [February 14, 2015, 11:00am UTC](https://community.f5.com/t/need-help-to-redirect-all-url-from-http-to-https/19885/4 "2015-02-14T11:00:28Z")

</div>

Also can you please explain me difference between url and uri

---

<div class="post-metadata">

**Author:** ![StephanManthey](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@StephanManthey](https://community.f5.com/u/StephanManthey)\
**Post date:** [February 14, 2015, 11:34am UTC](https://community.f5.com/t/need-help-to-redirect-all-url-from-http-to-https/19885/5 "2015-02-14T11:34:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![StephanManthey](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@StephanManthey](https://community.f5.com/u/StephanManthey)\
**Post date:** [February 14, 2015, 11:43am UTC](https://community.f5.com/t/need-help-to-redirect-all-url-from-http-to-https/19885/6 "2015-02-14T11:43:02Z")

</div>

Hi together, the URL is the resource locator as entered in the browser: i.e. [http://www.domain.bit/mypath/myobject?myquery](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: [HTTP](https://clouddocs.f5.com/api/irules/HTTP.html) Thanks, Stephan

---

<div class="post-metadata">

**Author:** ![Brad\_Parker](https://avatars.discourse-cdn.com/v4/letter/b/a87d85/32.png) [@Brad\_Parker](https://community.f5.com/u/Brad_Parker)\
**Post date:** [February 15, 2015, 11:58pm UTC](https://community.f5.com/t/need-help-to-redirect-all-url-from-http-to-https/19885/7 "2015-02-15T23:58:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![together\_183451](https://avatars.discourse-cdn.com/v4/letter/t/919ad9/32.png) [@together\_183451](https://community.f5.com/u/together_183451)\
**Post date:** [February 16, 2015, 11:17am UTC](https://community.f5.com/t/need-help-to-redirect-all-url-from-http-to-https/19885/8 "2015-02-16T11:17:30Z")

</div>

Hi Stephan, It is working Thanks for your help

---

<div class="post-metadata">

**Author:** ![StephanManthey](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@StephanManthey](https://community.f5.com/u/StephanManthey)\
**Post date:** [February 16, 2015, 11:24am UTC](https://community.f5.com/t/need-help-to-redirect-all-url-from-http-to-https/19885/9 "2015-02-16T11:24:26Z")

</div>

Thanks for the feedback! 🙂
