Amazon Route 53 with Lightsail and Naked Domain Redirecting
(Update in June 2019: you might want consider using the Bitnami Configuration tool which should solve this)
Using Amazon Route 53 (for both domain registration and DNS) has its advantages. Today I bought a new test domain and once it is set up in Route 53, a hosted zone was immediately set up and within seconds, the domain was already easily accessible. It was quick and fast.
But using Amazon Route 53 has its pain. Some functionalities in traditional domain registers are painfully missing in Route 53.
Why we cannot do re-directing of naked domain in Route 53
An example is re-directing of naked domain. What that means is when you enter “patnotebook.com”, you will be automatically directed to “www.patnotebook.com” (if that’s what you want). To do that in traditional domain registers, it is easy.
E.g. Enom with Google Apps
The point is, for better or worst, it is just there in one of the settings.
In Amazon Route 53, that does not work easily. Don’t believe ? Today I bought a new domain. Once it is registered (and using S3 bucket for static page hosting), the DNS Propagation was quick and the web page was working.
For this domain, the naked domain worked:
For this domain, out of the box, the www domain DOES NOT work:
How to solve this issue of Naked Domain Redirecting
So what can we do. There are a few solutions. One of which is using Amazon S3 (yet another paying service) to do so. For some of my clients’ web site that runs WordPress on Amazon Lightsail, I choose to use the redirect method at the application level (Apache and WordPress).
The key to this is this article: How To Redirect Myapp.example.com To Www.myapp.example.com?. This is because I choose www.example.com as my “main” domain (i.e www.patnotebook.com is my “main” domain).
So here’s goes…
Add the following in the httpd-vhosts.conf file for your application. Or, to apply this redirection by default for all applications installed, add it to the default VirtualHost in the /opt/bitnami/apache2/conf/bitnami.conf file.
(1) Locate httpd-vhosts.conf file
(2) Make the changes in the file
The final changes look like this:
(3) Locate bitnami-apps-vhosts.conf file
(4) Make changes to the file bitnami-apps-vhosts.conf
(5) Restart apache: sudo /opt/bitnami/ctlscript.sh restart apache
That’s all 🙂
Remember you are making changes at the Apache and Application level to overcome an issue at the domain level.