How to forward http request to https in Amazon Route53?

huzeyfe picture huzeyfe · Aug 29, 2012 · Viewed 22.4k times · Source

I have a subdomain in Amazon Route53. Let's say secure.example.com

If requests come like https://secure.example.com it is ok but I would like to force http requests to come through https. When user types http://secure.example.com it needs to be forwarded to https://secure.example.com.

Is there a domain level redirecting/forwarding requests coming through http to https in Amazon Route53?

Answer

Neal Magee picture Neal Magee · Oct 22, 2012

No, there is no way to do this -- because it's not a DNS function to force any particular protocol, or to push values from one protocol to another. You can do this easily enough at the web server level, either in Apache, or IIS, or NGINX.

In any of those cases, the A or CNAME value pointing a specific record to a specific address (whether an IP or another host name) is the same, it's just going to connect via port 80 or port 443.

In Apache, you can simply use a rewrite (enable mod_rewrite first):

RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://www.host.com/$1 [R]