Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Global External Load balance www to non www redirect

Hi,

I have deployed our website as a Cloud Run service.

Added a load balancer as per the doc listed in this link https://cloud.google.com/run/docs/integrate/custom-domain-load-balancer

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

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

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

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

 

Now I am able to redirect www.abc.com to https://abc.com . However if I access www.abc.com/page1, it redirects me to https://abc.com instead of https://abc.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

 

Solved Solved
2 2 848
1 ACCEPTED 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.

View solution in original post

2 REPLIES 2

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.

I believe that your problem was in setting stripQuery to true.  Something like:

name: path-matcher-www-redirect
defaultUrlRedirect:
  httpsRedirect: true
  stripQuery: false
  hostRedirect: "abc.com"
  redirectResponseCode: MOVED_PERMANENTLY_DEFAULT

should work.