1
votes

Here's my set up:

EC2 with Apache using elastic load balancer.

I'm looking to have all http traffic redirect automatically to https. I found this reco and tried it by adding to my httpd.conf file:

<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
</VirtualHost>

However, this didn't work before or after I restarted the server. HTTP didn't redirect and my sites threw all sorts of errors until I removed the rule from my config.

I'm thinking that I'm updating the file wrong or have the load balancer set up incorrectly. For the listeners for the load balancer I have LB protocol HTTP with port 80 with instance protocol HTTP and instance port 80. I have LB protocol HTTPS on port 443 with instance port 443. My SSL is on this latter protocol.

Any idea where to head from here?

1
Please include the errors. Also include the relevant apache conf that shows how your site is configured. - tedder42

1 Answers

3
votes

The configuration that you have mentioned should work well. The problem might be that the mod_rewrite module is not loaded. Add below lines to your apache configuration to load rewrite module.

LoadModule rewrite_module modules/mod_rewrite.so

You can try below configuration which is much simpler than what you are using.

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}