# independant from case-sensitive URI path httpS redirect

**URL:** <https://community.f5.com/t/independant-from-case-sensitive-uri-path-https-redirect/30862>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [March 11, 2011, 3:10pm UTC](https://community.f5.com/t/independant-from-case-sensitive-uri-path-https-redirect/30862 "2011-03-11T15:10:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![DM\_5174](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@DM\_5174](https://community.f5.com/u/DM_5174)\
**Post date:** [March 11, 2011, 3:10pm UTC](https://community.f5.com/t/independant-from-case-sensitive-uri-path-https-redirect/30862/1 "2011-03-11T15:10:27Z")

</div>

Hi All,

I was wondering if I could get some help from all of the i-rule gurus here.

Below is an i-rule we have that will 1) add “www” to the URI if a user forgets to put it in, and

2) if the user specify “/Mgt/Portal/LogOn” in the URI (for example [http://www.abc.test.com/Mgt/Portal/LogOn](http://www.abc.test.com/Mgt/Portal/LogOn)" they will get redirected to HTTPS “[httpS://www.abc.test.com/Mgt/Portal/LogOn](httpS://www.abc.test.com/Mgt/Portal/LogOn)”.

Currently we only want to trigger this because by default site [www.abc.com](http://www.abc.com) should NOT be HTTPS.

1. Is there a way to make it where if the the path “/Mgt/Portal/LogOn” can independant from case-sensitive charaters? So if the user puts /MgT/porTal/login" you still get HTTPS

2. And also consolidate this into a effcient irule and not use two “if” statment?

Thanks all in advance!

-DM

```tcl
when HTTP_REQUEST { 
             if { [HTTP::host] equals "abc.test.com" } { 
                   HTTP::redirect "http://www.abc.test.com[HTTP::uri]" 
                } 
             if { [HTTP::path] equals "/Mgt/Portal/LogOn" } { 
                  HTTP::redirect "https://www.abc.test.com[HTTP::uri]" 
                }

```

---

<div class="post-metadata">

**Author:** ![Chris\_Miller](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/chris_miller/32/14702_2.png) [@Chris\_Miller](https://community.f5.com/u/Chris_Miller)\
**Post date:** [March 11, 2011, 4:26pm UTC](https://community.f5.com/t/independant-from-case-sensitive-uri-path-https-redirect/30862/2 "2011-03-11T16:26:51Z")

</div>

1. Use “string tolower” before whatever you’re trying to check.

2. Since your redirects are different, an if might be best.

```tcl
when HTTP_REQUEST {
          if { [HTTP::host] eq "abc.test.com" } {
                HTTP::redirect "http://www.abc.test.com[HTTP::uri]" 
         } elseif { [string tolower [HTTP::uri]] starts_with "/mgt/portal/login" } {
                HTTP::redirect "https://www.abc.test.com[HTTP::uri]" }
        }

```

Interested to see if others have tips on optimizing.

---

<div class="post-metadata">

**Author:** ![DM\_5174](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@DM\_5174](https://community.f5.com/u/DM_5174)\
**Post date:** [March 11, 2011, 6:10pm UTC](https://community.f5.com/t/independant-from-case-sensitive-uri-path-https-redirect/30862/3 "2011-03-11T18:10:37Z")

</div>

Hi Chris,

For some reason this did not work. We need to make it exactly like this “/Mgt/Portal/LogIn” since the link is case-sensitive on the backend server no matter how the user puts in the uri path.

For example if the users puts [http://www.abc.test.com/mgt/portal/login](http://www.abc.test.com/mgt/portal/login) in the address bar, they should get [https://www.abc.test.com/Mgt/Portal/LogIn](https://www.abc.test.com/Mgt/Portal/LogIn)" by the i-rule.

Also, this rule also disable the function where users adding in “[abc.test.com/abc](http://abc.test.com/abc)”, it does not append the “www”. It shoudl be http"[//www.abc.com/abc](https://www.abc.com/abc)".

Thanks again,

-DM

---

<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:** [March 11, 2011, 6:46pm UTC](https://community.f5.com/t/independant-from-case-sensitive-uri-path-https-redirect/30862/4 "2011-03-11T18:46:15Z")

</div>

That looks good to me Chris 🙂

Aaron

---

<div class="post-metadata">

**Author:** ![Chris\_Miller](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/chris_miller/32/14702_2.png) [@Chris\_Miller](https://community.f5.com/u/Chris_Miller)\
**Post date:** [March 11, 2011, 7:52pm UTC](https://community.f5.com/t/independant-from-case-sensitive-uri-path-https-redirect/30862/5 "2011-03-11T19:52:45Z")

</div>

Try this:

```tcl
when HTTP_REQUEST {
          if { [HTTP::host] eq "abc.test.com" } {
                HTTP::redirect "http://www.abc.test.com[HTTP::uri]" 
         } elseif { [string tolower [HTTP::uri]] starts_with "/mgt/portal/login" } {
                HTTP::redirect "https://[HTTP::host][HTTP::uri]" }
        }

```

---

<div class="post-metadata">

**Author:** ![Chris\_Miller](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/chris_miller/32/14702_2.png) [@Chris\_Miller](https://community.f5.com/u/Chris_Miller)\
**Post date:** [March 11, 2011, 7:55pm UTC](https://community.f5.com/t/independant-from-case-sensitive-uri-path-https-redirect/30862/6 "2011-03-11T19:55:11Z")

</div>

Wait - are you saying someone who puts in [abc.test.com/abc](http://abc.test.com/abc) isn’t being redirected to [www.abc.test.com/abc](http://www.abc.test.com/abc) ?

The redirect will honor the case. The user’s request is stored in [HTTP::uri] so referencing that within the redirect keeps it as is.

Currently - what’s the behavior you’re seeing and what would you like to see? 😉

---

<div class="post-metadata">

**Author:** ![Austin\_Geraci](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/austin_geraci/32/28655_2.png) [@Austin\_Geraci](https://community.f5.com/u/Austin_Geraci)\
**Post date:** [March 13, 2011, 4:59pm UTC](https://community.f5.com/t/independant-from-case-sensitive-uri-path-https-redirect/30862/7 "2011-03-13T16:59:19Z")

</div>

I think I see what He’s looking for..

For some reason this did not work. We need to make it exactly like this “/Mgt/Portal/LogIn” since the link is case-sensitive on the backend server no matter how the user puts in the uri path.

He wants the actual redirect to be case sensitive, but the detection to be insensitive… Soo, after to you set your string to lower for the detection, specify the actual uri for redirection, “/Mgt/Portal/LogIn”

Not sure either why the append for ‘www’ isn’t working for you, looks fine..

---

<div class="post-metadata">

**Author:** ![Chris\_Miller](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/chris_miller/32/14702_2.png) [@Chris\_Miller](https://community.f5.com/u/Chris_Miller)\
**Post date:** [March 13, 2011, 6:21pm UTC](https://community.f5.com/t/independant-from-case-sensitive-uri-path-https-redirect/30862/8 "2011-03-13T18:21:44Z")

</div>

DM - can you confirm iRuleYou is describing what you want to see? I guess we could do some sort of string map for this.

---

<div class="post-metadata">

**Author:** ![DM\_5174](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@DM\_5174](https://community.f5.com/u/DM_5174)\
**Post date:** [March 14, 2011, 1:23pm UTC](https://community.f5.com/t/independant-from-case-sensitive-uri-path-https-redirect/30862/9 "2011-03-14T13:23:02Z")

</div>

Hey Guys,

When I used “/Mgt/Portal/LogIn” It worked (gave me httpS) even if I went in with lower case. The funny thing is when I specify the opposite, lower case “/mgt/portal/login”, it does not redirect me to httpS. For some reason our application requires specific case sensitive letters in order to present you with the login page, but now I am getting the SSL connection and everything else seems to work when I re-ordered things around in the code.

I think we are good. Thanks Chris!

-DM
