Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

www -> nonwww redirect for many domains #38466

Open
dolgovas opened this issue Feb 15, 2025 · 1 comment
Open

www -> nonwww redirect for many domains #38466

dolgovas opened this issue Feb 15, 2025 · 1 comment
Labels
area/router question Questions that are neither investigations, bugs, nor enhancements

Comments

@dolgovas
Copy link

I can't find any directive for massive host_rewrite configuration.
I want to make something like this

www.example.com    301 to example.com
www.example1.com   301 to example1.com
www.example2.com   301 to example2.com
www.example3.com   301 to exampel3.com

I tried to use route like this

 kind: Route
 metadata:
   name: www-redirect
 spec:
   - name: www-redirect
     match:
       prefix: "/"
     redirect:
       https_redirect: true
       regex_rewrite:
         pattern:
           google_re2: {}
          regex: "^www\\.(.*)$"
        substitution: "\\1"

But I realized that regex_rewrite works only with path, but not with host.

For now, I use this construction

routeConfigurations:
  - name: exc-configs/www
    virtual_hosts:
      - name: exc-configs/www
        domains:
          - www.example.com
        routes:
          - name: www-redirect
            match:
              PathSpecifier:
                Prefix: /
            Action:
              Redirect:
                SchemeRewriteSpecifier:
                  HttpsRedirect: true
                host_redirect: example.com
---
routeConfigurations:
  - name: exc-configs/www
    virtual_hosts:
      - name: exc-configs/www
        domains:
          - www.example1.com
        routes:
          - name: www-redirect
            match:
              PathSpecifier:
                Prefix: /
            Action:
              Redirect:
                SchemeRewriteSpecifier:
                  HttpsRedirect: true
                host_redirect: example1.com
---
routeConfigurations:
  - name: exc-configs/www
    virtual_hosts:
      - name: exc-configs/www
        domains:
          - www.example2.com
        routes:
          - name: www-redirect
            match:
              PathSpecifier:
                Prefix: /
            Action:
              Redirect:
                SchemeRewriteSpecifier:
                  HttpsRedirect: true
                host_redirect: example2.com
---
routeConfigurations:
  - name: exc-configs/www
    virtual_hosts:
      - name: exc-configs/www
        domains:
          - www.example3.com
        routes:
          - name: www-redirect
            match:
              PathSpecifier:
                Prefix: /
            Action:
              Redirect:
                SchemeRewriteSpecifier:
                  HttpsRedirect: true
                host_redirect: example3.com

And it works. But may be I can improve it?

@dolgovas dolgovas added the triage Issue requires triage label Feb 15, 2025
@adisuissa adisuissa added question Questions that are neither investigations, bugs, nor enhancements area/router and removed triage Issue requires triage labels Feb 18, 2025
@adisuissa
Copy link
Contributor

I'm aware of a few host-rewrite options, but I'm not sure these answer your use-case.
Another option would be to add an explicit filter that rewrites the host header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/router question Questions that are neither investigations, bugs, nor enhancements
Projects
None yet
Development

No branches or pull requests

2 participants