# redirect http://www.{URI} & http://{URI} to https://{URI}

**URL:** <https://community.f5.com/t/redirect-http-www-uri-http-uri-to-https-uri/38600>\
**Category:** Technical Forums\
**Tags:** irules, big-ip, application-delivery\
**Created:** [July 16, 2017, 10:09am UTC](https://community.f5.com/t/redirect-http-www-uri-http-uri-to-https-uri/38600 "2017-07-16T10:09:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mofathy\_63257](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mofathy\_63257](https://community.f5.com/u/mofathy_63257)\
**Post date:** [July 16, 2017, 10:09am UTC](https://community.f5.com/t/redirect-http-www-uri-http-uri-to-https-uri/38600/1 "2017-07-16T10:09:38Z")

</div>

Hi We have a situation where the published website is needs http to https redirect and in the same time gives an error when accessed using www.{URI}

So may you help with the iRule syntax that : redirect both .{URI} & http://{URI} to https://{URI}, ofcourse while keeping the full URI path without change

---

<div class="post-metadata">

**Author:** ![mofathy\_63257](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mofathy\_63257](https://community.f5.com/u/mofathy_63257)\
**Post date:** [July 16, 2017, 10:12am UTC](https://community.f5.com/t/redirect-http-www-uri-http-uri-to-https-uri/38600/2 "2017-07-16T10:12:33Z")

</div>

Just an update: besides the above needs, it’s also needed to redirect .{URI} to https://{URI}

---

<div class="post-metadata">

**Author:** ![Patrik\_Jonsson](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/patrik_jonsson/32/20827_2.png) [@Patrik\_Jonsson](https://community.f5.com/u/Patrik_Jonsson)\
**Post date:** [July 16, 2017, 10:39am UTC](https://community.f5.com/t/redirect-http-www-uri-http-uri-to-https-uri/38600/3 "2017-07-16T10:39:04Z")

</div>

The question is not entirely clear but if all you want is to redirect to https you might want to have a look at this pre-generated iRule (it comes with all modern versions of TMOS):

/Common/\_sys\_https\_redirect

---

<div class="post-metadata">

**Author:** ![Patrik\_Jonsson](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/patrik_jonsson/32/20827_2.png) [@Patrik\_Jonsson](https://community.f5.com/u/Patrik_Jonsson)\
**Post date:** [July 16, 2017, 11:32am UTC](https://community.f5.com/t/redirect-http-www-uri-http-uri-to-https-uri/38600/4 "2017-07-16T11:32:03Z")

</div>

I would split it into two rules.

Apply this to the HTTP VIP:

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

```

Apply this to the HTTPS VIP:

```tcl
when HTTP_REQUEST {

    if { [HTTP::host] eq "www.test.com" } {
        HTTP::respond 302 Location "https://test.com[HTTP::uri]"
    }       

}

```

That should take care of all the scenarios you mentioned.

/Patrik

---

<div class="post-metadata">

**Author:** ![Mohamed\_Fathy](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Mohamed\_Fathy](https://community.f5.com/u/Mohamed_Fathy)\
**Post date:** [August 7, 2020, 2:20am UTC](https://community.f5.com/t/redirect-http-www-uri-http-uri-to-https-uri/38600/5 "2020-08-07T02:20:09Z")

</div>

Hi,

Although it’s an old question, but it was just tested now!!

We’ve applied it but didn’t work, noting that our domain is in the format of : subdomain.domain.com.eg , so may the long format of domain causes an issue? any workarounds?
