# HTTPS offload rewriting

**URL:** <https://community.f5.com/t/https-offload-rewriting/67114>\
**Category:** Community CodeShare\
**Tags:** content-manipulation, irules, devops, application-delivery\
**Created:** [March 18, 2015, 6:48pm UTC](https://community.f5.com/t/https-offload-rewriting/67114 "2015-03-18T18:48:17Z")\
**Posts on this page:** 8\
**Page:** 1

<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 18, 2015, 6:48pm UTC](https://community.f5.com/t/https-offload-rewriting/67114/1 "2015-03-18T18:48:17Z")

</div>

**Problem this snippet solves:**

This iRule shows how to rewrite an HTTP web application’s self references from http:// to https:// to avoid insecure content warnings.

**Note if the response content size is changed like it would be with this iRule you must use a custom HTTP profile with response chunking set to rechunk.**

**Code :**

```auto
when HTTP_REQUEST {

# Save the requested host value
set host [string tolower [HTTP::host]]

# If the HTTP host header is blank, use the VS IP address
# If the VS IP is not routable for clients, hard code a routable IP
# to replace [IP::local_addr]
if {$host eq ""}{set host [IP::local_addr]}

# Disable the stream filter by default
STREAM::disable
}
when HTTP_RESPONSE {

# Check if response type is text and host isn't null
if {[HTTP::header value Content-Type] contains "text" and $host ne ""}{

# Replace http://$host with https://$host
STREAM::expression "@http://$host@https://$host@"

# Enable the stream filter for this response only
STREAM::enable

}
# Rewrite the Location header in redirects to https://
if { [HTTP::is_redirect] && [string tolower [HTTP::header Location]] starts_with "http://$host"} {
HTTP::header replace Location [string map -nocase "http://$host https://$host" [HTTP::header Location]]
}
}

```

---

<div class="post-metadata">

**Author:** ![r\_dynamo\_79563](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@r\_dynamo\_79563](https://community.f5.com/u/r_dynamo_79563)\
**Post date:** [August 13, 2015, 6:20pm UTC](https://community.f5.com/t/https-offload-rewriting/67114/2 "2015-08-13T18:20:55Z")

</div>

Hi Aaron, There are some HTTP references that are not being displayed at all using above iRule (HTTPS VIP) even after enabling mixed content on the browser. I have a HTTP & HTTPS VIP. Streaming is enabled on the HTTPS VIP, and the HTTP VIP has a generic http to https redirect: when HTTP\_REQUEST { HTTP::redirect https://[HTTP::host][HTTP::uri] } Both the VIPs have a custom http profile with Server Response set to “Rechunk,” and a custom destination address persistence profile to match across pools in different virtual Servers. Any further suggestions will be highly appreciated.

---

<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:** [September 29, 2015, 12:41am UTC](https://community.f5.com/t/https-offload-rewriting/67114/3 "2015-09-29T00:41:08Z")

</div>

Hi R, Can you add debug logging to the iRule and post the anonymized log output and a sample of the server response payloads which are not being rewritten? Thanks, Aaron

---

<div class="post-metadata">

**Author:** ![sprashanthac\_81](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@sprashanthac\_81](https://community.f5.com/u/sprashanthac_81)\
**Post date:** [March 17, 2016, 7:14pm UTC](https://community.f5.com/t/https-offload-rewriting/67114/4 "2016-03-17T19:14:51Z")

</div>

There seems to be a natural behaviour to change the post request as get request. The access method is being altered when using http to https rule. Is there a way to have it fixed. don’t want to alter the http method and keep it intact when HTTP\_REQUEST { HTTP::redirect https://[HTTP::host][HTTP::uri] } changes the method for POST to GET and breaking our application is there a way to fix it. Seems like this is the usual behavior of F5

---

<div class="post-metadata">

**Author:** ![AndresG\_241389](https://avatars.discourse-cdn.com/v4/letter/a/df788c/32.png) [@AndresG\_241389](https://community.f5.com/u/AndresG_241389)\
**Post date:** [May 18, 2016, 10:58am UTC](https://community.f5.com/t/https-offload-rewriting/67114/5 "2016-05-18T10:58:38Z")

</div>

A 301/2 redirect will instruct the requester to reissue the request as a GET… You must a 307

---

<div class="post-metadata">

**Author:** ![subrud\_297411](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@subrud\_297411](https://community.f5.com/u/subrud_297411)\
**Post date:** [October 31, 2016, 4:52am UTC](https://community.f5.com/t/https-offload-rewriting/67114/6 "2016-10-31T04:52:56Z")

</div>

Where to paste this code?

---

<div class="post-metadata">

**Author:** ![Tewfik\_Megherbi](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@Tewfik\_Megherbi](https://community.f5.com/u/Tewfik_Megherbi)\
**Post date:** [May 30, 2017, 8:43am UTC](https://community.f5.com/t/https-offload-rewriting/67114/7 "2017-05-30T08:43:19Z")

</div>

If you get errors from browser about XMLHttpRequest response server being send over http.

Error message might be : Mixed Content: The page at ‘https:/xxxx.com/zzz.html’ was loaded over HTTPS, but requested an insecure resource ‘[http://xxxx.com/b/ttt.css](http://xxxx.com/b/ttt.css)’. This request has been blocked; the content must be served over HTTPS."

Make sure you assign a compression profile to the VS that runs this irule.

This is because STREAM function requires that server response to be decompressed before hand.

---

<div class="post-metadata">

**Author:** ![kazeem\_yusuf1](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kazeem\_yusuf1](https://community.f5.com/u/kazeem_yusuf1)\
**Post date:** [June 5, 2017, 11:02pm UTC](https://community.f5.com/t/https-offload-rewriting/67114/8 "2017-06-05T23:02:17Z")

</div>

Hello Hoolio. I used the irule after application owner was getting a 'Blocked loading mixed active content" on his webpage.

However,after applying the Your irule, i get error [https://agilitycareuat.kazeem.com.ng:80/UserManagement/com/ericsson/usermanagement/userlogin/fetchLoginLoc.do?username=testuser1](https://agilitycareuat.kazeem.com.ng:80/UserManagement/com/ericsson/usermanagement/userlogin/fetchLoginLoc.do?username=testuser1).

It appends a port 80,after making a request with test user “testuser1”. If however,i remove the port 80. The request goes fine.

What is the solution to this?
