# redirect http  requests to https

**URL:** <https://community.f5.com/t/redirect-http-requests-to-https/24752>\
**Category:** Technical Forums\
**Tags:** irules, ltm, application-delivery\
**Created:** [January 23, 2019, 12:43am UTC](https://community.f5.com/t/redirect-http-requests-to-https/24752 "2019-01-23T00:43:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SP\_266134](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@SP\_266134](https://community.f5.com/u/SP_266134)\
**Post date:** [January 23, 2019, 12:43am UTC](https://community.f5.com/t/redirect-http-requests-to-https/24752/1 "2019-01-23T00:43:30Z")

</div>

Hi Guys, I have a two vips one is at 443 and another one dummy vip with same address at port 80 for http traffic. when users go to all works fine. with other vip if user goes [http://domain.com](http://domain.com), it is redirecting to https but SSL are lost. here is the Irule when HTTP\_REQUEST {

HTTP::redirect https://[HTTP::host][HTTP::uri] }

in order to solve this issues I am planning to add add “www” like this in the below script. As I dont have test environment setup i want to confirm with some experts before i try. Any suggestion are also welcome.

when HTTP\_REQUEST { HTTP::redirect “.[HTTP::host][HTTP::uri]” } }

---

<div class="post-metadata">

**Author:** ![Dylan\_375544](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dylan\_375544](https://community.f5.com/u/Dylan_375544)\
**Post date:** [January 23, 2019, 12:52am UTC](https://community.f5.com/t/redirect-http-requests-to-https/24752/2 "2019-01-23T00:52:29Z")

</div>

There is actually an iRule built into BIG-IP for that purpose.

[HERE](https://devcentral.f5.com/questions/http-to-https-redirect-minimum-requirements-for-http-virtual-server) is actually a DevCentral article on it with some good info in the comments.

Hope that helps! If it does please up-vote and select this answer, it’d be greatly appreciated!

-Dylan

---

<div class="post-metadata">

**Author:** ![JG](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@JG](https://community.f5.com/u/JG)\
**Post date:** [January 23, 2019, 1:06am UTC](https://community.f5.com/t/redirect-http-requests-to-https/24752/3 "2019-01-23T01:06:36Z")

</div>

Try this one:

```tcl
when HTTP_REQUEST { 
    if { not ([string tolower [HTTP::host]] starts_with "www.") } {
        HTTP::redirect "https://www.[HTTP::host][HTTP::uri]"
    } else {
        HTTP::redirect "https://[HTTP::host][HTTP::uri]"    
    } 
}

```

.

---

<div class="post-metadata">

**Author:** ![Kai\_Wilke](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kai_wilke/32/24646_2.png) [@Kai\_Wilke](https://community.f5.com/u/Kai_Wilke)\
**Post date:** [January 23, 2019, 1:23pm UTC](https://community.f5.com/t/redirect-http-requests-to-https/24752/4 "2019-01-23T13:23:02Z")

</div>

Hi SP,

if is the only web application on the IP, then simply redirect to a fixed HOST-value. It will work in any case…

```tcl
when HTTP_REQUEST {
    HTTP::respond 301 "Location" "https://www.domain.com[HTTP::uri]"
     HTTP::respond 302 "Location" "https://www.domain.com[HTTP::uri]"
}

```

_ **Note:** If you don’t use HTTP to access your web site and also not plan to use it in the future, then it would be far more elegant to send a 301 (Permanent Redirect) instead of 302 (Temporary Redirect) response. Thecommand can only send 301 (Temporary Redirect) responses, but thecommand can either send aorredirect response (see example above)._

```tcl
HTTP::redirect

```

```tcl
HTTP::respond

```

```tcl
301

```

```tcl
302

```

Cheers, Kai
