# HTTPS to HTTP Redirection changes required

**URL:** <https://community.f5.com/t/https-to-http-redirection-changes-required/18638>\
**Category:** Technical Forums\
**Tags:** irules, cloud\
**Created:** [May 20, 2016, 8:05am UTC](https://community.f5.com/t/https-to-http-redirection-changes-required/18638 "2016-05-20T08:05:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![VijayKumarBC\_25](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@VijayKumarBC\_25](https://community.f5.com/u/VijayKumarBC_25)\
**Post date:** [May 20, 2016, 8:05am UTC](https://community.f5.com/t/https-to-http-redirection-changes-required/18638/1 "2016-05-20T08:05:40Z")

</div>

Below redirection iRule is working for - [https://www.my.com](https://www.my.com)

But Not working for [https://my.com](https://my.com)

Please suggest if there are any changes required

when HTTP\_REQUEST { set HOST [string tolower [HTTP::host]] set URI [string tolower [HTTP::uri]]

```tcl
Start switch host
 switch -glob $HOST {
 "my.com" - "www.my.com"
     {
       HTTP::respond 301 Location "http://www.my.com"
     }
  }

```

}

---

<div class="post-metadata">

**Author:** ![VijayKumarBC\_25](https://avatars.discourse-cdn.com/v4/letter/v/71e660/32.png) [@VijayKumarBC\_25](https://community.f5.com/u/VijayKumarBC_25)\
**Post date:** [May 20, 2016, 8:06am UTC](https://community.f5.com/t/https-to-http-redirection-changes-required/18638/2 "2016-05-20T08:06:36Z")

</div>

when HTTP\_REQUEST { set HOST [string tolower [HTTP::host]] set URI [string tolower [HTTP::uri]]

```tcl
Start switch host
 switch -glob $HOST {
 "my.it" - "www.my.it"
     {
       HTTP::respond 301 Location "http://www.my.it"
     }
  }

```

}

---

<div class="post-metadata">

**Author:** ![VernonWells](https://avatars.discourse-cdn.com/v4/letter/v/dec6dc/32.png) [@VernonWells](https://community.f5.com/u/VernonWells)\
**Post date:** [May 20, 2016, 9:15am UTC](https://community.f5.com/t/https-to-http-redirection-changes-required/18638/3 "2016-05-20T09:15:23Z")

</div>

That rule should work fine. I suggest adding logging. In addition, is there more to the iRule? If not, I recommend strongly against setting

```tcl
$URI

```

. In fact, it’s sub-optimal to set

```tcl
$HOST

```

as a variable, unless it is going to be used more than once. Normally, in programming, coding defensively and optimizing for readability and maintenance efficiency is sensible, but that’s not the case with iRules. If one must choose between those things and performance, you almost always want to choose performance, since it executes with each connection (or, in the case of the rule below, each HTTP Request received). Finally, the use of

```tcl
-glob

```

on the

```tcl
switch

```

should be used only if you intend to perform glob matching. For strict matching, it’s about 10% faster to exclude the

```tcl
-glob

```

. Perhaps give this a try:

```tcl
when HTTP_REQUEST {
    switch [string tolower [HTTP::host]] {
    "my.com" -
    "www.my.com" {
        log local0. "Matched HTTP::host = [HTTP::host]"
        HTTP::respond 301 Location "http://www.my.com"
    }
}

```

Look in

```tcl
/var/log/ltm

```

for the log message. If it does not match when you are going to _[https://my.com](https://my.com)_, then try the following:

```tcl
when HTTP_REQUEST {
    log local0. "Host header = [string tolower [HTTP::host]]"
    switch [string tolower [HTTP::host]] {
    "my.com" -
    "www.my.com" {
        HTTP::respond 301 Location "http://www.my.com"
    }
}

```

and try the request, again looking in

```tcl
/var/log/ltm

```

(be aware that, if the request rate is quite high, the log may be suppressed, and you may end up with a lot of logging!). Once you are done testing, don’t forget to remove the logging statements, of course.
