Search code examples
amazon-web-servicesamazon-ec2amazon-elastic-beanstalkamazon-elb

How to route regular domain entry to secure port 443 using Elastic Beanstalk


I have PHP website (will call it awesomedomain.com from now on.) currently load balanced in Elastic Beanstalk with SSL up and running.

I can obtain a secure connection to the site with https://awesomedomain.com/ however whenever I enter "awesomedomain.com" it still connects as unsecure port.

I have two listeners 80 and 443 set-up. How can I route all coming traffic to port 443 for global SSL connection?

Thanks to anyone beforehand.

Cheers,

~bio


Solution

  • You can set two ways :

    1. Setup rule is host file :
    NameVirtualHost *:80
    <VirtualHost *:80>
       ServerName abc.example.com
       Redirect permanent / https://abc.example.com/
    </VirtualHost>
    
    <VirtualHost _default_:443>
       ServerName abc.example.com
      DocumentRoot /var/www/html/example
      SSLEngine On 
    </VirtualHost>
    

    Don't forget to restart server after this changes.

    1. In .htaccess file :
    RewriteEngine On
    
    RewriteCond %{HTTPS} off 
    
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
    
    1. If you are using CloudFront and ELB as endpoint for ssl certificate then CloudFront has option to redirect http to https all request.