I have a Flask app that I use Zappa to deploy. I have successfully deployed it to www.my_domain.com . But a lot of folks have told me "your site's down" and when I followed up it's because they go to https://my_domain.com (no www).
I'd like to redirect from that to the working site. My certificate is via AWS and technically for www.my_domain.com, *.my_domain.com, and my_domain.com (though when I did the email-based approval *.my_domain.com and my_domain.com both were interpreted as my_domain.com).
I've tried changing my zappa_settings.json domain but no change.
For purposes of this answer, I'm assuming that the bare domain is the secondary and the
wwwis the primary. If you choose the opposite, simply reverse the terms while reading.Redirect one site to the other
Redirection means that the browser can load
my_domain.combut receives the HTTP response of 301 moved permanently. This means that the browser is redirected towww.my_domain.comand navigates to that site.The user sees the address bar changed to be
www.my_domain.com(although many browsers now hide thewwwpart of the address), and new page loads.Redirection requires some type of HTTP server running at
my_domain.com. If you already have an HTTP server running, then it's pretty straightforward to configure the web server to send the redirect.If you don't have a server, then you can use a static web site service like S3, Github, Netlify to provide the redirect.
It is kind of annoying to have to set up an entire web server to just send a 301 code. But this method is well understood and well supported.
Alias one site to the other
Alias means that both
my_domain.comandwww.my_domain.comwork and use only one Zappa project. It's like two doors that go into the same room.The browser's address bar doesn't change and the user operates on the site normally. One caveat of this approach is to be a little more careful if you are using cookies to make sure they are shared between the two domains.
Aliasing requires some advanced configuration of AWS services.
API Gateway configuration
www.my_domain.com)my_domain.com)Edge optimizedmy_domain.com)Route 53 configuration
Arecord (CNAMEif you are doing the reverse)wwwdomain name (www.my_domain.com)172800will cache requests for two days, which is not too bad.ACM configuration
You'll have to ensure that the certificate covers both
my_domain.comandwww.my_domain.com.Zappa configuration
Make sure to add both domain names in
ALLOWED_HOSTSotherwise Django will reject the request.