skip to Main Content

There’s an SEO issue where we have duplicate domains ..

For example – www.domain.com and domain.com.
I would like to recreate a 301 redirect from the apex website (www.domain.com) to the non-apex URL (domain.com)

Our UI application is hosted on GCP/GKE. I have found annotations for nginx type ingress to create such redirect .. but in our case, we’re using GCP native ingress instead.

Any help or documentation will be highly appreciated. Nothing I found currently suits my needs.

2

Answers


  1. Chosen as BEST ANSWER

    I was able to configure the apex to non apex redirect using the following YAML configuration

       defaultService: global/backendServices/<YOUR-BACKEND-SERVICE-NAME> # Non apex load balancer backend
       name: global-lb-map
       hostRules:
       - hosts:
         - 'www.domain.co.il'
         pathMatcher: www-matcher
       pathMatchers:
       - defaultService: global/backendServices/<YOUR-BACKEND-SERVICE-NAME>
         name: www-matcher
         routeRules:
           - matchRules:
               - prefixMatch: /
             priority: 1
             urlRedirect:
               hostRedirect: "domain.co.il"
               redirectResponseCode: MOVED_PERMANENTLY_DEFAULT
               stripQuery: True
    

    Saving the file as redirect.yaml, and then apply using gcloud compute url-maps import global-lb-map --source .redirect.yaml --global

    'target-https-proxies' and 'forwarding-rules' resources have to be configured aswell.

    the following commands may be used

    target-https-proxies

    • Ceate an SSL certificate or use the one already attached to your apex domain
    gcloud compute target-https-proxies create https-proxy 
        --url-map=global-lb-map 
        --ssl-certificates=ssl-cert 
        --global
    

    forwarding-rules

    • Create a static IP first.
    gcloud compute forwarding-rules create https-forwarding-rule 
        --address=[YOUR_GLOBAL_STATIC_IP_ADDRESS_NAME] 
        --global 
        --target-https-proxy=https-proxy 
        --ports=443
    

    When all 3 have been configured, make sure you remove the apex domain from your ingress configuration field and create an A type DNS record pointing the APEX to the newly created static IP that was assigned with your load balancer.

    You will then be able to see the redirect succeed.

    enter image description here

    Thanks @JanMaroon for your help.


Please signup or login to give your own answer.
Back To Top
Search