Skip to content

Commit

Permalink
Docs: Clarify from-to-www redirect direction. (#11693)
Browse files Browse the repository at this point in the history
* 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 <service@chakrit.net>
Co-authored-by: Marco Ebert <marco_ebert@icloud.com>
  • Loading branch information
3 people authored Jul 29, 2024
1 parent 5bfe327 commit 2eefef9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docs/user-guide/nginx-configuration/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/ingress/annotations/redirect/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 2eefef9

Please sign in to comment.