I have a subdomain called for example : hello.example.com. I can access this url using hello.example.com or https://hello.example.com.
The problem is that some of our customers use www.hello.example.com which doesnt show the website.I tried multiple redirection methods. But none is working perfectly.
Our environment : The website is hosted in 4 aws instances with 2 haproxy load balancers(total 6 instances). The domain is routed in aws Route 53.
I Tried 3 methods: 1. Adding a redirect rule in haproxy.cfg file "redirect prefix hello.example.com code 301 if { hdr(host) -i www.hello.example.com }"
Adding rewrite rule in .htaccess file in my document root
By adding www.hello.example.com in route53 ad route it to a s3 bucket with same name and using static website hosting to redirect it to hello.example.com
I am getting ssl certificate error while using the 1st method. I think this has something to do with the url being a subdomain.I have wildcard certificate for *.example.com . So this doesnt work for www.hello.example.com
The second method doesnt do anything.
And with third method i sometimes get the website using www, but not always. If i clear my cache and then search for it i will git using www, but only for 1 time.