# Redirect from WWW iRule

**URL:** <https://community.f5.com/t/redirect-from-www-irule/52404>\
**Category:** Technical Forums\
**Tags:** irules, big-ip, ltm, application-delivery\
**Created:** [May 6, 2021, 12:13pm UTC](https://community.f5.com/t/redirect-from-www-irule/52404 "2021-05-06T12:13:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yanik](https://avatars.discourse-cdn.com/v4/letter/y/ccd318/32.png) [@Yanik](https://community.f5.com/u/Yanik)\
**Post date:** [May 6, 2021, 12:13pm UTC](https://community.f5.com/t/redirect-from-www-irule/52404/1 "2021-05-06T12:13:43Z")

</div>

Hello all !

How can I redirect traffic from “[www.example.com](http://www.example.com)” to “[https://example.com](https://example.com)”, I don’t care if it’s an iRule or policy.

I tried iRules, policies, and nothing worked, all other redirects I created work fine.

Thanks, Yan

---

<div class="post-metadata">

**Author:** ![Enes\_Afsin\_Al](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/enes_afsin_al/32/15359_2.png) [@Enes\_Afsin\_Al](https://community.f5.com/u/Enes_Afsin_Al)\
**Post date:** [May 6, 2021, 2:34pm UTC](https://community.f5.com/t/redirect-from-www-irule/52404/2 "2021-05-06T14:34:33Z")

</div>

Hi Yan,

1. string map

```tcl
when HTTP_REQUEST {
	if { [HTTP::host] starts_with "www." } {
		HTTP::redirect https://[string map {www. ""} [HTTP::host]][HTTP::uri]
	}
}

```

2. string range

```tcl
when HTTP_REQUEST {
	if { [HTTP::host] starts_with "www." } {
		HTTP::redirect https://[string range [HTTP::host] 4 end][HTTP::uri]
	}
}

```

3. getfield

```tcl
when HTTP_REQUEST {
	if { [HTTP::host] starts_with "www." } {
		HTTP::redirect https://[getfield [HTTP::host] "www." 2][HTTP::uri]
	}
}

```

4. substr

```tcl
when HTTP_REQUEST {
	if { [HTTP::host] starts_with "www." } {
		HTTP::redirect https://[substr [HTTP::host] 4][HTTP::uri]
	}
}

```

---

<div class="post-metadata">

**Author:** ![Yanik](https://avatars.discourse-cdn.com/v4/letter/y/ccd318/32.png) [@Yanik](https://community.f5.com/u/Yanik)\
**Post date:** [May 6, 2021, 2:55pm UTC](https://community.f5.com/t/redirect-from-www-irule/52404/3 "2021-05-06T14:55:33Z")

</div>

Thanks for the answer, but no one of the iRules doesn’t work.

When I log the iRule I see “SSL Handshake failed for TCP”, so may be I have some other issue and not iRule, so I will investigate it.

---

<div class="post-metadata">

**Author:** ![AlexBCT](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@AlexBCT](https://community.f5.com/u/AlexBCT)\
**Post date:** [May 6, 2021, 8:15pm UTC](https://community.f5.com/t/redirect-from-www-irule/52404/4 "2021-05-06T20:15:27Z")

</div>

Hi Yanik,

That sounds like a different issue indeed. You may want to confirm that you have the iRule attached to the port 80 virtual server, rather than the 443 virtual server. Also, check that the port 80 virtual server doesn’t have any SSL profiles on it.

Or if it is supposed to be redirected from **https:/** /www.example.com to [https://example.com](https://example.com), then you DO need an SSL profile on the virtual server, so that the iRule can read the unencrypted request.

Hope this helps.
