# Redirect HTTP request to HTTPS VS and rewrite new URI

**URL:** <https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258>\
**Category:** Technical Forums\
**Tags:** deployment, big-ip-access-policy-manager-apm, irules, oracle, security, devops, application-delivery\
**Created:** [January 22, 2014, 1:22pm UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258 "2014-01-22T13:22:29Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramil\_Ancajas\_1](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ramil\_Ancajas\_1](https://community.f5.com/u/Ramil_Ancajas_1)\
**Post date:** [January 22, 2014, 1:22pm UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258/1 "2014-01-22T13:22:29Z")

</div>

Hi I have a service HTTPS VS with client SSL profile to offload SSL. It has two member server pool running on service tcp 9994. The site is to be accessed either using HTTP or HTTPS by using the VS IP only in the URL, i.e., [https://VS-IP](https://VS-IP) or [HTTP://VS-IP](HTTP://VS-IP), hence the user wants the LTM to be able to redirect HTTP traffic to HTTPS. And also we want to rewrite traffic as [http://pool-member-ip:9994/xyz-uri](http://pool-member-ip:9994/xyz-uri) when LTM forwards the request to the server pool.

Can anyone help me suggest an irule for this?

Appreciate your support. Ramil

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [January 22, 2014, 1:40pm UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258/2 "2014-01-22T13:40:10Z")

</div>

user wants the LTM to be able to redirect HTTP traffic to HTTPS. And also we want to rewrite traffic as [http://pool-member-ip:9994/xyz-uri](http://pool-member-ip:9994/xyz-uri) when LTM forwards the request to the server pool.

https virtual server will change vs-ip to pool-member-ip:9994 itself. what you have to do is to redirect from http to https and change uri from / to /xyz-uri.

e.g.

```tcl
config
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
ltm virtual bar {
    destination 172.28.24.10:80
    ip-protocol tcp
    mask 255.255.255.255
    profiles {
        http { }
        tcp { }
    }
    rules {
        qux
    }
    source 0.0.0.0/0
    vs-index 3
}
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
ltm rule qux {
    when HTTP_REQUEST {
  if { [HTTP::uri] eq "/" } {
    HTTP::redirect "https://[HTTP::host]/xyz-uri"
  }
}
}

 test

[root@ve11a:Active:In Sync] config curl -I http://172.28.24.10
HTTP/1.0 302 Found
Location: https://172.28.24.10/xyz-uri
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

```

---

<div class="post-metadata">

**Author:** ![Ramil\_Ancajas\_1](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ramil\_Ancajas\_1](https://community.f5.com/u/Ramil_Ancajas_1)\
**Post date:** [January 22, 2014, 2:18pm UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258/3 "2014-01-22T14:18:09Z")

</div>

Hi Nitass,

thank you for your quick response.

However I tried it and seems still not working. We actually wanted to have the LTM to do the SSL offloading first (terminate the SSL from client request) and then forward the request to pool member with appended URI (/xyz). When I tested your irule, it redirected traffic to the pool member using with HTTPS protocol plus the appended URI. It didnt work because the pool server do not accept HTTPS..

Thanks anyway but I do appreciate anymore suggestion please… Ramil

---

<div class="post-metadata">

**Author:** ![nitass](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/nitass/32/2270_2.png) [@nitass](https://community.f5.com/u/nitass)\
**Post date:** [January 22, 2014, 2:22pm UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258/4 "2014-01-22T14:22:17Z")

</div>

When I tested your irule, it redirected traffic to the pool member using with HTTPS protocol plus the appended URI. It didnt work because the pool server do not accept HTTPS..

where did you apply the irule? was it http virtual server (not https virtual server)?

the irule will redirect from http virtual server to https virtual server with appending uri. on the https virtual server, it will offload ssl and send http (not https) to pool member.

---

<div class="post-metadata">

**Author:** ![nitass\_89166](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@nitass\_89166](https://community.f5.com/u/nitass_89166)\
**Post date:** [January 22, 2014, 2:22pm UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258/5 "2014-01-22T14:22:17Z")

</div>

When I tested your irule, it redirected traffic to the pool member using with HTTPS protocol plus the appended URI. It didnt work because the pool server do not accept HTTPS..

where did you apply the irule? was it http virtual server (not https virtual server)?

the irule will redirect from http virtual server to https virtual server with appending uri. on the https virtual server, it will offload ssl and send http (not https) to pool member.

---

<div class="post-metadata">

**Author:** ![Ramil\_Ancajas\_1](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ramil\_Ancajas\_1](https://community.f5.com/u/Ramil_Ancajas_1)\
**Post date:** [January 23, 2014, 8:59am UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258/6 "2014-01-23T08:59:02Z")

</div>

Thank you very much Nitass. I created another HTTP VS and assigned the irule there and it works! Much appreciated. Ramil

---

<div class="post-metadata">

**Author:** ![Ramil\_Ancajas\_1](https://avatars.discourse-cdn.com/v4/letter/r/b782af/32.png) [@Ramil\_Ancajas\_1](https://community.f5.com/u/Ramil_Ancajas_1)\
**Post date:** [January 23, 2014, 8:59am UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258/7 "2014-01-23T08:59:02Z")

</div>

Thank you very much Nitass. I created another HTTP VS and assigned the irule there and it works! Much appreciated. Ramil

---

<div class="post-metadata">

**Author:** ![midhun\_108442](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@midhun\_108442](https://community.f5.com/u/midhun_108442)\
**Post date:** [January 21, 2015, 4:35am UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258/8 "2015-01-21T04:35:58Z")

</div>

Hi,

Yes we are using Redirect Rewrite option in the http profile , This is our setup, Client --\> BigIP (443) BigIP --\> Webserver (80) We use the http redirect rewrite profile as “All”. With this We are able to get our webserver Loging page and able to login successfull , But after that if we click any tab or option on the webpage it again redirect to http,

I had applied default irule “\_sys\_https\_redirect” but here i am not getting the login page itself and verfied the logs no packet has been sent to the pool member.

appreciate your help please.

Regards, Midhun P.K

---

<div class="post-metadata">

**Author:** ![chells2\_241915](https://avatars.discourse-cdn.com/v4/letter/c/48db29/32.png) [@chells2\_241915](https://community.f5.com/u/chells2_241915)\
**Post date:** [February 9, 2016, 8:44am UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258/9 "2016-02-09T08:44:26Z")

</div>

Hi, Is not the loadbalancer do application layer first, means.It will first do the SSL termination for https URL and then it will look for irules to redirect right ? I see in your comment, for http traffic from client loadbalancer will check for the irules then it will go with the SSL termination.

---

<div class="post-metadata">

**Author:** ![chells2\_241915](https://avatars.discourse-cdn.com/v4/letter/c/48db29/32.png) [@chells2\_241915](https://community.f5.com/u/chells2_241915)\
**Post date:** [February 9, 2016, 8:44am UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258/10 "2016-02-09T08:44:26Z")

</div>

Hi, Is not the loadbalancer do application layer first, means.It will first do the SSL termination for https URL and then it will look for irules to redirect right ? I see in your comment, for http traffic from client loadbalancer will check for the irules then it will go with the SSL termination.

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [February 9, 2016, 9:09am UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258/11 "2016-02-09T09:09:47Z")

</div>

Chells2, you cannot “see” the (application layer) HTTP traffic until you’ve first terminated the SSL. BIG-IP iRules events work in the same order as OSI layers.

---

<div class="post-metadata">

**Author:** ![Kevin\_Stewart](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kevin_stewart/32/15267_2.png) [@Kevin\_Stewart](https://community.f5.com/u/Kevin_Stewart)\
**Post date:** [February 9, 2016, 9:09am UTC](https://community.f5.com/t/redirect-http-request-to-https-vs-and-rewrite-new-uri/19258/12 "2016-02-09T09:09:47Z")

</div>

Chells2, you cannot “see” the (application layer) HTTP traffic until you’ve first terminated the SSL. BIG-IP iRules events work in the same order as OSI layers.
