# Help: Redirect to https with URI

**URL:** <https://community.f5.com/t/help-redirect-to-https-with-uri/25192>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [August 5, 2008, 2:20pm UTC](https://community.f5.com/t/help-redirect-to-https-with-uri/25192 "2008-08-05T14:20:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Girish\_HS\_32793](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@Girish\_HS\_32793](https://community.f5.com/u/Girish_HS_32793)\
**Post date:** [August 5, 2008, 2:20pm UTC](https://community.f5.com/t/help-redirect-to-https-with-uri/25192/1 "2008-08-05T14:20:03Z")

</div>

Hi Team,

I have a iRule setup for http which checks for URI and assigns the Node & port to be used.

when HTTP\_REQUEST {

if { [HTTP::host] equals “[mysite.someplace.com](http://mysite.someplace.com)”} {

if { [HTTP::uri] starts\_with “/abc” } {

node 10.244.8.34 9001

}

}

}

Now I need to redirect [http://mysite.someplace.com](http://mysite.someplace.com) to [https://mysite.someplace.com](https://mysite.someplace.com), check for URI and use specific node and port.

How do I achieve this?

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [August 6, 2008, 5:16am UTC](https://community.f5.com/t/help-redirect-to-https-with-uri/25192/2 "2008-08-06T05:16:05Z")

</div>

Checking the URI and using a specific IP and port is what the rule you posted does. Can you clarify what you’re trying to accomplish?

Thanks,

Aaron

---

<div class="post-metadata">

**Author:** ![Girish\_HS\_32793](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@Girish\_HS\_32793](https://community.f5.com/u/Girish_HS_32793)\
**Post date:** [August 6, 2008, 9:58am UTC](https://community.f5.com/t/help-redirect-to-https-with-uri/25192/3 "2008-08-06T09:58:24Z")

</div>

Hi Aaron, I will try to explain what I need to accomplish.

I have a total of 4 apps registered to 1 Public IP address, All the 4 apps have a specific homepage, out of the 4 apps I have one app which has its specific home page and also running another application which is determined by its URI.

As of now I have setup a iRule which will look for the HOST and redirect it to its specific homepage. All the 4 HOST’s have different names.

What I want to accomplish is, (1) I want to redirect all HTTP request for the 4 apps to HTTPS and (2) as said, one of the 4 apps is also using a different application which is determined by the URI, I want to redirect this application also to HTTPS and also this application runs on one of the nodes where as the others are hosted on 2 nodes and loadbalanced.

the present setup is like this:

1) [http://order.asia.com/homepage\_asia](http://order.asia.com/homepage%5C_asia)

2) [http://order.asia.com/xyz](http://order.asia.com/xyz)

3) [http://order.aus.com/homepage\_aus](http://order.aus.com/homepage%5C_aus)

4) [http://order.amr.com/homepage\_amr](http://order.amr.com/homepage%5C_amr)

5) [http://order1.eur.com/homepage\_eur](http://order1.eur.com/homepage%5C_eur)

I have setup a iRule to redirect 1,3,4,5 (URL’s mentioned above) to its homepage and users who wish to use the application [http://order.asia.com/xyz](http://order.asia.com/xyz) hit it directly.

My Requirement:

I have a single new Zone created with SSL certificate assigned to it

Redirect all HTTP to HTTPS to its specific URI and when I redirect [http://order.asia.com/xyz](http://order.asia.com/xyz)

it should use just one node.

like when a client browse the 4 HTTP URL’s he should be redirected to HTTPS URL for example if I browse [http://order.asia.com](http://order.asia.com) I should get redirected to [https://allinone.order.com/homepage\_asia](https://allinone.order.com/homepage%5C_asia) and when I hit [http://order.asia.com/xyz](http://order.asia.com/xyz) it should get redirected to [https://allinone.order.com/xyz](https://allinone.order.com/xyz)

Thanks & Regards,

Giri

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [August 6, 2008, 11:58am UTC](https://community.f5.com/t/help-redirect-to-https-with-uri/25192/4 "2008-08-06T11:58:34Z")

</div>

Hi Giri,

You can check the host and/or URI with either if or switch statements. You can redirect the client to a new location using HTTP::redirect “[http://subdomain.example.com/path/to/file.ext](http://subdomain.example.com/path/to/file.ext)”.

Here is a simple example which uses both switch and if:

```tcl
when HTTP_REQUEST { 
  
     Check requested hostname 
    switch [string tolower [HTTP::host]] { 
       "order.asia.com" { 
          if {[HTTP::uri] starts_with "/homepage_asia"}{ 
             log local0. "[IP::client_addr]:[TCP::client_port]: Matched order.asia.com/hompage_asia. \ 
                Redirecting to https://order.asia.com[HTTP::uri]" 
             HTTP::redirect "https://order.asia.com[HTTP::uri]" 
          } else { 
             log local0. "[IP::client_addr]:[TCP::client_port]: Matched order.asia.com. Using pool http_pool" 
             pool $http_pool 
          } 
       } 
       "order.aus.com" { 
          log local0. "[IP::client_addr]:[TCP::client_port]: Matched order.aus.com. Redirecting to https://order.aus.com[HTTP::uri]" 
          HTTP::redirect "https://order.aus.com[HTTP::uri]" 
       } 
       default { 
          log local0. "[IP::client_addr]:[TCP::client_port]: Hit default clause." 
          HTTP::redirect "https://default.asia.com[HTTP::uri]" 
       } 
    } 
 }

```

This rule would be applied to the single HTTP VIP. I didn’t try to follow your exact logic, but hopefully you can use the syntax to implement your requirements.

If all four domains currently resolve to the same IP address, you’ll need one SSL certificate which is valid for all of the hostnames. Or you’ll need to change the DNS to resolve to separate IP’s and use separate SSL certificates.

Aaron
