From 2eefef9845bd37611b5bbd46086943f92abe2086 Mon Sep 17 00:00:00 2001 From: k8s-infra-cherrypick-robot <90416843+k8s-infra-cherrypick-robot@users.noreply.github.com> Date: Mon, 29 Jul 2024 02:55:14 -0700 Subject: [PATCH] Docs: Clarify `from-to-www` redirect direction. (#11693) * docs: Clarify from-to-www redirect direction. This was not clear to me when reading the docs whether the ingress will redirect from non-www to with-www or the reverse. It's also not very clear from just grepping around the codebase. I found the answer by reading from this reddit link: https://www.reddit.com/r/kubernetes/comments/pbl033/k8s_ingress_redirecting_www_to_nonwww_domains/ So, to save time for other people doing the same, which I assumes is a lot of people since it's a common scenario, this little revision in the docs is warranted. * Docs: Implement suggestion. --------- Co-authored-by: Chakrit Wichian Co-authored-by: Marco Ebert --- docs/user-guide/nginx-configuration/annotations.md | 5 ++++- internal/ingress/annotations/redirect/redirect.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/user-guide/nginx-configuration/annotations.md b/docs/user-guide/nginx-configuration/annotations.md index 47ebd30e3..f90e87868 100755 --- a/docs/user-guide/nginx-configuration/annotations.md +++ b/docs/user-guide/nginx-configuration/annotations.md @@ -655,7 +655,10 @@ To preserve the trailing slash in the URI with `ssl-redirect`, set `nginx.ingres ### Redirect from/to www -In some scenarios is required to redirect from `www.domain.com` to `domain.com` or vice versa. +In some scenarios, it is required to redirect from `www.domain.com` to `domain.com` or vice versa, which way the redirect is performed depends on the configured `host` value in the Ingress object. + +For example, if `.spec.rules.host` is configured with a value like `www.example.com`, then this annotation will redirect to `example.com`. If `.spec.rules.host` is configured with a value like `example.com`, so without a `www`, then this annotation will redirect to `www.example.com` instead. + To enable this feature use the annotation `nginx.ingress.kubernetes.io/from-to-www-redirect: "true"` !!! attention diff --git a/internal/ingress/annotations/redirect/redirect.go b/internal/ingress/annotations/redirect/redirect.go index b58e35171..e774b2fe8 100644 --- a/internal/ingress/annotations/redirect/redirect.go +++ b/internal/ingress/annotations/redirect/redirect.go @@ -51,7 +51,7 @@ var redirectAnnotations = parser.Annotation{ Validator: parser.ValidateBool, Scope: parser.AnnotationScopeLocation, Risk: parser.AnnotationRiskLow, // Low, as it allows just a set of options - Documentation: `In some scenarios is required to redirect from www.domain.com to domain.com or vice versa. To enable this feature use this annotation.`, + Documentation: `In some scenarios, it is required to redirect from www.domain.com to domain.com or vice versa, which way the redirect is performed depends on the configured host value in the Ingress object.`, }, temporalRedirectAnnotation: { Validator: parser.ValidateRegex(parser.URLIsValidRegex, false),