1

I've created a wordpress blog with Amazon Lightsail and bought several domain names on route 53. My main domain is example.com, I've also bought:

  • example.eu
  • example.be
  • etc.

I'm using s3 buckets to redirect every possible combination (with non www and with www) to www.example.com (in my hosted zone in route 53 it is www.example.com that is redirected to my lightsail static IP).

I've installed a Lets Encrypt SSL certificate for www.example.com

Now I would like to force HTTPS so that all requests redirect to https://www.example.com (usin 301 redirect) which I'm able to do using my s3 buckets but I'm not able to redirect www.example.com to https://www.example.com as it's associated to my static IP address.

What should I do to allow access to my blog only through HTTPS? I've searched for quite some time on the net and found some tutorials saying that I should use cloudfront to handle redirection to HTTPS but they never really apply to my situation.

jimdb
  • 31
  • 1
  • 6
  • This is a simple matter of configuring the web server on your Lightsail machine to generate the redirect to https when the request isn't already https. Nothing specific to Lightsail. The first Google hit for `stack overflow nginx redirect http to https` is https://stackoverflow.com/a/21113549/1695906. Change "nginx" to "Apache" if you're not running nginx. – Michael - sqlbot Jan 14 '18 at 16:57
  • Thanks Michael, I've solved my issue with this link: [link](https://community.bitnami.com/t/change-http-to-https-in-my-wordpress-aws-bitnami-hosting/47246) Truth is I'm new to this and I thought I had to do something specific to Lightsail by using S3 or Cloudfront and got really confused. Do you think it's better to use S3 buckets to redirect from secondary domains to my main domain or just do it in the server config? – jimdb Jan 15 '18 at 13:58
  • It depends on several factors. If your server is providing `https://www.example.com` then you can't use a bucket to redirect `http://www.example.com` because everything at a given hostname can only be handled by one entity (though that entity may then delegate certain operations downstream, for example CloudFront). For simple redirects of one hostname to another, I like the CloudFront + S3 configuration because it's simple, has no maintenance, and won't likely break unless you do something that breaks it. – Michael - sqlbot Jan 15 '18 at 15:09
  • Lightsail is simply a VPS, and you are free to do essentially anything with it that you could do with any server, anywhere, with limited exceptions (such as sending spam, where there are measures in place to block that). It can interact with other AWS services as much or as little as you want it to -- there's no requirement to use any other AWS services with it, but there are often advantages when you do. – Michael - sqlbot Jan 15 '18 at 15:11
  • Please consider writing and posting an answer explaining what you did, with code (config) examples, and explain what it does, why it is the solution, and give attribution to the original document you found. A point to keep in mind is thst there needs to be enough information in the answer that the answer itself solves the problem in the event that the off-site link becomes unavailable, but do this without excessive copy/paste, being sure that it's clear which words aren't your own (using `>` to prefix blockquotes and citing the source, of course). Also add your web server to the question tags. – Michael - sqlbot Jan 15 '18 at 15:16

1 Answers1

2

So I've finally figured it out thanks to this post. I've modified the httpd-app.conf file to add an SSL redirection rule:

RewriteEngine On
RewriteBase /

#SSL redirection
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Rewrite index.php
RewriteRule ^index\.php$ - [S=1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

This rule allows to redirect all HTTP calls to HTTPS using the SSL certificate I installed on my server (for the domain www.example.com).

jimdb
  • 31
  • 1
  • 6