AWS Elasticbeanstalk单实例强制SSL

时间:2013-12-03 21:40:48

标签: php .htaccess codeigniter ssl amazon-web-services

我正在为我的应用程序使用aws elasticbeanstalk单个实例。我尝试了所有解决方案来强制ssl。我的意思是即使用户转到http://myapp.com我希望它重定向https://myapp.com。我尝试了所有mod_rewrite .htaccess解决方案,并且我尝试使用我的codeigniter控制器中的php重定向功能重定向,但它们无法正常工作。

这是我的.htaccess配置:

#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]

3 个答案:

答案 0 :(得分:1)

如果您遵循AWS文档,则来自端口443的每个呼叫都将代理到端口80.排除localhost并且它应该可以工作:

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

答案 1 :(得分:0)

尝试更换:

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

RewriteCond %{HTTPS} off

答案 2 :(得分:0)

强制HTTPS规则:

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