Yusuf Can Gürkan
Yusuf Can Gürkan

Reputation: 765

AWS Elasticbeanstalk Single Instance Force SSL

I'm using aws elasticbeanstalk single instance for my application. I tried all solutions to force ssl. I mean even though user goes to http://myapp.com i want it to redirect https://myapp.com. I tried all mod_rewrite .htaccess solutions and also i tried to redirect by using php redirect function in my codeigniter controller and they didn't work.

Here is my .htaccess configuration:

#Force SSL
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Upvotes: 1

Views: 408

Answers (3)

Marcin Pajdzik
Marcin Pajdzik

Reputation: 116

If you had followed the AWS docs, every call from port 443 is proxyed to port 80. Exclude localhost and it should work:

RewriteCond %{SERVER_PORT} !=443
RewriteCond %{SERVER_ADDR}   !^127\.0\.0\.1
RewriteRule (.*) https://%{SERVER_NAME}/$1 [L]

Upvotes: 1

anubhava
anubhava

Reputation: 785008

Force HTTPS rule:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !status https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

Upvotes: 0

Jon Lin
Jon Lin

Reputation: 143876

Try replacing:

RewriteCond %{HTTP:X-Forwarded-Proto} !https

with

RewriteCond %{HTTPS} off

Upvotes: 0

Related Questions