# Redirecting HTTP to HTTPS

**URL:** <https://discuss.konghq.com/t/redirecting-http-to-https/2637>\
**Category:** Questions\
**Tags:** kubernetes\
**Created:** [January 17, 2019, 3:41pm UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637 "2019-01-17T15:41:19Z")\
**Posts on this page:** 16\
**Page:** 2

<div class="post-metadata">

**Author:** ![hbagdi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hbagdi/32/562_2.png) [@hbagdi](https://discuss.konghq.com/u/hbagdi)\
**Post date:** [September 10, 2019, 4:55pm UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/21 "2019-09-10T16:55:17Z")

</div>

The Route object in Kong now supports `https_redirect_status_code`, please use that to setup HTTP to HTTPS redirection:

> **[Open-Source API Management and Microservice Management](https://docs.konghq.com/1.3.x/admin-api/#route-object)**
>
> Secure, Manage & Extend your APIs or Microservices with plugins for authentication, logging, rate-limiting, transformations and more.

---

<div class="post-metadata">

**Author:** ![HYUN\_SUK\_JUNG](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hyun_suk_jung/32/1122_2.png) [@HYUN\_SUK\_JUNG](https://discuss.konghq.com/u/HYUN_SUK_JUNG)\
**Post date:** [September 11, 2019, 12:10am UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/22 "2019-09-11T00:10:34Z")

</div>

Thank you  
How can we apply https-redirect at kong ingress?

---

<div class="post-metadata">

**Author:** ![Sothy\_Lorn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/sothy_lorn/32/1316_2.png) [@Sothy\_Lorn](https://discuss.konghq.com/u/Sothy_Lorn)\
**Post date:** [September 11, 2019, 2:51am UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/23 "2019-09-11T02:51:52Z")

</div>

Hi @alexjantunen could you tell me how to redirect http to https on kong with docker?  
Thank

---

<div class="post-metadata">

**Author:** ![Sothy\_Lorn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/sothy_lorn/32/1316_2.png) [@Sothy\_Lorn](https://discuss.konghq.com/u/Sothy_Lorn)\
**Post date:** [September 11, 2019, 6:21am UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/24 "2019-09-11T06:21:52Z")

</div>

Hi @hbinduni I use it too but doesn’t work brother. ![32%20AM](https://canada1.discourse-cdn.com/flex036/uploads/konghq/original/2X/e/e1f6df870f3a1b5f61d569f31488a57681feb286.png)

---

<div class="post-metadata">

**Author:** ![Sothy\_Lorn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/sothy_lorn/32/1316_2.png) [@Sothy\_Lorn](https://discuss.konghq.com/u/Sothy_Lorn)\
**Post date:** [September 11, 2019, 6:26am UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/25 "2019-09-11T06:26:07Z")

</div>

Hi @bgarcial thank for your reply but i want to ask you about this code. Where that i put this code or where that I run this code?  
echo "apiVersion: [configuration.konghq.com/v1](http://configuration.konghq.com/v1)  
kind: KongIngress  
metadata:  
name: https-only  
route:  
protocols:

- https  
https\_redirect\_status\_code: 302  
" | kubectl apply -f -  
[kongingress.configuration.konghq.com/https-only](http://kongingress.configuration.konghq.com/https-only) created

---

<div class="post-metadata">

**Author:** ![bgarcial](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/bgarcial/32/776_2.png) [@bgarcial](https://discuss.konghq.com/u/bgarcial)\
**Post date:** [September 16, 2019, 12:42pm UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/26 "2019-09-16T12:42:05Z")

</div>

You can create the `KongIngress` resource of a separate way, for instance:

```auto
# This KongIngress resource should be created first before to
# create kong basic-auth KongPlugin and Priva Ingress resource.

apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
  name: customer-ingress
  # namespace: default
  annotations:
    kubernetes.io/ingress.class: "kong"
proxy:
  protocols:
    - http
    - https
# path: /
route:
  methods:
    - POST
    - GET
  strip_path: true
  preserve_host: true

```

And execute it.

---

<div class="post-metadata">

**Author:** ![dcherniv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/dcherniv/32/1380_2.png) [@dcherniv](https://discuss.konghq.com/u/dcherniv)\
**Post date:** [October 10, 2019, 1:44am UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/27 "2019-10-10T01:44:14Z")

</div>

@hbagdi  
I doesn’t work correctly for me:

```auto
{
  "id": "229254f5-e430-4210-ae69-b467cb4f626e",
  "tags": [
    "managed-by-ingress-controller"
  ],
  "updated_at": 1570666150,
  "destinations": null,
  "headers": null,
  "protocols": [
    "http",
    "https"
  ],
  "created_at": 1570666150,
  "snis": null,
  "service": {
    "host": "prod-cleric.prod.svc",
    "created_at": 1570666150,
    "connect_timeout": 60000,
    "id": "1b04066f-52d4-46d5-8e51-0c44eb0efafe",
    "protocol": "http",
    "name": "prod.prod-cleric.80",
    "read_timeout": 60000,
    "port": 80,
    "path": "/",
    "updated_at": 1570666150,
    "retries": 5,
    "write_timeout": 60000,
    "tags": [
      "managed-by-ingress-controller"
    ],
    "client_certificate": null,
    "extras": {}
  },
  "name": "prod.prod-cleric.00",
  "preserve_host": true,
  "regex_priority": 0,
  "strip_path": true,
  "sources": null,
  "paths": [
    "/v2/cleric"
  ],
  "https_redirect_status_code": 426,
  "hosts": [
    "REDACTED"
  ],
  "methods": null
}

```

looks https\_redirect\_status\_code is set on the route.  
“https\_redirect\_status\_code”: 426,  
however no redirect when i trigger the endpoint via plaintext http.

```auto
curl -v -H "apiKey: REDACTED=" http://REDACTED/v2/cleric/description/?text=foo
[...]
* TCP_NODELAY set
* Expire in 149970 ms for 3 (transfer 0x5591812c8dd0)
* Expire in 200 ms for 4 (transfer 0x5591812c8dd0)
* Connected to REDACTED (10.160.32.80) port 80 (#0)
> GET /v2/cleric/description/?text=foo HTTP/1.1
> Host: REDACTED
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: application/vnd.siren+json
< Content-Length: 1300
< Connection: keep-alive
< Server: gunicorn/19.9.0
< Date: Thu, 10 Oct 2019 01:40:25 GMT
< X-Kong-Upstream-Latency: 39
< X-Kong-Proxy-Latency: 1
< Via: kong/1.3.0
[...]

```

\*\* NINJA EDIT  
It looks like for the 426 to work, http needs to be removed from the list of protocols on the route.  
“A list of the protocols this Route should allow. By default it is [“http”, “https”], which means that the Route accepts both. When set to [“https”], HTTP requests are answered with a request to upgrade to HTTPS.”

---

<div class="post-metadata">

**Author:** ![Raunak\_Khatri](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/raunak_khatri/32/1403_2.png) [@Raunak\_Khatri](https://discuss.konghq.com/u/Raunak_Khatri)\
**Post date:** [December 12, 2019, 11:41am UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/28 "2019-12-12T11:41:01Z")

</div>

Hi @hbagdi and @bgarcial,

I have created the plugin as mentioned above. But the problem I am facing is, the service call is going in 302 redirect loop and then at last after few, it fails.

That is each time I am getting http requests, even after 302 redirection which converting http to https.

The manifest file is as below,

> ```
> apiVersion: configuration.konghq.com/v1
> kind: KongPlugin
> metadata:
> name: https-redirect
> labels:
> global: "false"
> plugin: pre-function
> config:
> functions:
> - |
> local scheme = kong.request.get_scheme()
> if scheme == "http then
> local host = kong.request.get_host()
> local query = kong.request.get_path_with_query()
> local url = "https://" .. host ..query
> kong.response.set_header("Location",url)
> return kong.response.exit(302,url)
> end
> 
> ```

Please help.  
Thanks

---

<div class="post-metadata">

**Author:** ![hbagdi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hbagdi/32/562_2.png) [@hbagdi](https://discuss.konghq.com/u/hbagdi)\
**Post date:** [December 12, 2019, 7:22pm UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/29 "2019-12-12T19:22:33Z")

</div>

This is now supported by Kong itself and doesn’t require a plugin.  
Please take a look at the `https_redirect_status_code` property of the `route` entity.

---

<div class="post-metadata">

**Author:** ![roger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/roger/32/2005_2.png) [@roger](https://discuss.konghq.com/u/roger)\
**Post date:** [July 23, 2020, 1:01am UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/31 "2020-07-23T01:01:51Z")

</div>

Is there a simple example of using https\_redirect\_status? The link you gave earlier takes me to docs I don’t follow, not sure they’re related to a kubernetes ingress which is where I’m trying to use this.

---

<div class="post-metadata">

**Author:** ![hbagdi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hbagdi/32/562_2.png) [@hbagdi](https://discuss.konghq.com/u/hbagdi)\
**Post date:** [July 28, 2020, 1:09am UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/32 "2020-07-28T01:09:46Z")

</div>

Please follow this guide: [https://github.com/Kong/kubernetes-ingress-controller/blob/master/docs/guides/configuring-https-redirect.md](https://github.com/Kong/kubernetes-ingress-controller/blob/master/docs/guides/configuring-https-redirect.md) for Kubernetes Ingress.

---

<div class="post-metadata">

**Author:** ![roger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/roger/32/2005_2.png) [@roger](https://discuss.konghq.com/u/roger)\
**Post date:** [July 30, 2020, 8:45pm UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/33 "2020-07-30T20:45:02Z")

</div>

I’m not sure what I did but it works now. Your guide suggested modifying the KongIngress but I left mine alone (it still has protocols http, https etc listed) ie same as the k4k8.yaml file I originally downloaded.  
My ingress annotations look like this:

```auto
    annotations = {
      "kubernetes.io/ingress.class" = "kong"
      "kubernetes.io/ingress.allow-http" = "false"
    }  

```

That second entry was left over from when I was using gcp so I don’t know if it is making the difference. Anyway it’s working so I’m happy.

---

<div class="post-metadata">

**Author:** ![greg](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@greg](https://discuss.konghq.com/u/greg)\
**Post date:** [December 15, 2020, 8:24pm UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/34 "2020-12-15T20:24:07Z")

</div>

It is still super disappointing that we have to create a KongPlugin instance to do this basic ingress function. When installing a service via a helm chart, this means we have to manually go though and either edit the helm chart or create the KongPlugin.

---

<div class="post-metadata">

**Author:** ![Lambert](https://avatars.discourse-cdn.com/v4/letter/l/e56c9b/32.png) [@Lambert](https://discuss.konghq.com/u/Lambert)\
**Post date:** [January 11, 2021, 6:32am UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/35 "2021-01-11T06:32:37Z")

</div>

kongingress seems a namespaced resource, and I don’t want to install it for each namespace to just force the https re-direct, so kindly please help to show the cluster-wide installation?

---

<div class="post-metadata">

**Author:** ![David\_Betterton](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/david_betterton/32/3615_2.png) [@David\_Betterton](https://discuss.konghq.com/u/David_Betterton)\
**Post date:** [September 2, 2022, 4:43pm UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/36 "2022-09-02T16:43:58Z")

</div>

> [@Raunak\_Khatri](#):
>
> `if scheme == "http then`

Looks like missing closing double quote after the http on this line

---

<div class="post-metadata">

**Author:** ![mloskot](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/mloskot/32/2259_2.png) [@mloskot](https://discuss.konghq.com/u/mloskot)\
**Post date:** [March 29, 2023, 4:55pm UTC](https://discuss.konghq.com/t/redirecting-http-to-https/2637/37 "2023-03-29T16:55:51Z")

</div>

Here are the annotations that I use for Kong/KIC setup on AKS and they seem to work fine:

```plaintext
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: app-0
  namespace: app
  annotations:
    konghq.com/https-redirect-status-code: "301"
    konghq.com/protocols: "https"
spec:
  ingressClassName: kong
  rules:
    - host: "app.contoso.com"
      http:
        paths:
        ...

```

[Previous page](https://discuss.konghq.com/t/redirecting-http-to-https/2637.md?page=1)
