network-programminggcp-load-balancer

GCP Global External Load balance redirect www to non www sites


I have deployed our website as a Cloud Run service.

Added a Global external load balancer as per the doc listed in this link here

Everything is perfect and My website is now runnings as https://example.com

I am currently exploring redirecting www.example.com to https://example.com .

Tried adding a Host and path rule by editing the custom-domains http with the following yaml config for www.example.com .

defaultService: projects/xyz/global/backendServices/custom-domains-example-com-example-49a4-be
name: matcher1
routeRules:
- urlRedirect:
stripQuery: true
hostRedirect: example.com
matchRules:
- prefixMatch: /
priority: 1

Now I am able to redirect www.example.com to https://example.com . However if I access www.example.com/page1, it redirects me to https://example.com instead of https://example.com/page1 .

Can you assist me on how can I acheive this.

Also, let me know if this is the best practice to be followed as well.

Regards

Srinivasan


Solution

  • I solved it myself as listed below.

    Instead of using the Loadbalancer listed above, I created a classic load balancer by following this link including setting up SSL certificate etc.

    Then added a redirect URL as per this example . It works now.

    Regards

    Srinivasan