Contour: Redirect: adding a redirect (301 or 302) option in ingressroute / httpproxy

Created on 3 Oct 2019  路  14Comments  路  Source: projectcontour/contour

Describe the solution you'd like
The ingressroute / httpproxy should be able to support a match and then redirect with either a 301 or 302 to an http or https destination

Something like:

spec:
  routes:
  - match: /
    services:
    - name: awesome-service-01
      port: 1000
   - match: /redirectpath
    redirect:
      method: 301
      destination: https://externalawesomewebsite.com
  virtualhost:
    fqdn: awesomehost.tld

Anything else you would like to add:
The use case would be that for example if you have a website pointed to the ingress you can now also do redirects in contour. This would prevent you from having to spin up another container inside for the redirect (nginx for example).

Environment:

  • Contour version: v1.0.0-beta.1
  • Kubernetes version: (use kubectl version): v1.14.6-gke.1
  • Kubernetes installer & version: N/A (Google)
  • Cloud provider or hardware configuration: GKE
  • OS (e.g. from /etc/os-release): GKE
blockeneeds-design kinfeature prioritimportant-longterm

Most helpful comment

Thank you for your feature request. I think I understand the use case. At the moment we're deep in feature freeze in preparation for Contour 1.0. I've assigned this to the backlog for prioritisation for a future release.

All 14 comments

This would be nice for dealing with redirecting 'example.comtowww.example.comor vice-versa. Currently, I'm running an nginx container whose only job is to redirect all requests towww.example.com`.

Thank you for your feature request. I think I understand the use case. At the moment we're deep in feature freeze in preparation for Contour 1.0. I've assigned this to the backlog for prioritisation for a future release.

Also needed from an SEO standpoint with the http to https or root_uri to www.root_uri

On 24 Jan 2020, at 2:59 am, PeopleRange notifications@github.com wrote:

Also needed from an SEO standpoint with the http to https or root_uri to www.root_uri

When TLS is enabled on a root HTTPProxy, the http -> https redirect is automatically provisioned.

https://projectcontour.io/docs/v1.1.0/httpproxy/#tls

A common use-case for this is redirecting www.stevesloka.com --> stevesloka.com which isn't the same as the tls redirect @jpeach

@jpeach Thank You for the link to the documentation. I already have this bit implemented my experience comes from Nginx which common practice especially if using hsts headers is to 301 redirects to http then 301 redirect to the canonical domain (If Any).

We have another use case here for Intranet websites -- users often rely on the DNS search path so they type "foo" instead of "foo.company.org". A 3xx redirect from the short form to the long form is often necessary. Being able to do this as the ingress proxy layer is more convenient than implementing this code in every web app / backend service.

From https://github.com/projectcontour/contour/issues/3014, some kinds of redirect will want to strip the query string. The example from that issue is:

spec:
  virtualhost: foo.example.com
  routes:
    - redirect:
        destination: bar.example.com  # required
        include_query_string: false      # default 

We require the same functionality to prevent the creation of a Pod specifically for a 301 Location redirect. Is there any update on feature prioritization?

Support for this got added in #3555 which adds DAG/Envoy support for direct responses. I think if we added a RedirectPolicy to the route that would make sense as proposed originally.

Yes, I think that adding something like a RedirectPolicy as an option in HTTPProxy would be great. The next step here is a design, but we'll need to review the prioritization of this issue in a triage meeting soon.

Is the redirection described above now possible using contour? I have a similar use case as described by the OP and I have not been able to get a working solution based on the documentation available at https://projectcontour.io/docs/v1.16.0/config/external-service-routing/

Hi @MichaelOgunsanmi, sorry but we haven't finished building this support out yet. #3555 added internal support for doing something similar to this (returning a 503 if the service is invalid), but we haven't added the ability to request a redirect on a specific route yet. We will need to be able to do this for the in-development upstream Gateway API, and we will backport similar functionality to HTTPProxy.

But, we haven't finished that yet, sorry.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonasrosland picture jonasrosland  路  6Comments

jedsalazar picture jedsalazar  路  6Comments

pandeykartikey picture pandeykartikey  路  3Comments

phylake picture phylake  路  4Comments

stevesloka picture stevesloka  路  6Comments