使用其他mod_rewrite规则在AWS Elastic Beanstalk负载均衡器上将HTTP重定向到HTTPS

时间:2017-08-13 02:42:19

标签: apache .htaccess amazon-web-services mod-rewrite

我在AWS Elastic Beanstalk上有一个Web应用程序,SSL正在运行,但我需要确保所有流量都是HTTPS。我认为与我们现有的规则或负载均衡器存在冲突。以下是我们的.htaccess文件中的规则:     RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteCond %{REQUEST_URI} !uploads
RewriteCond %{REQUEST_URI} !.*\.(css¦js|html|png|xml|mp3|m4a)
RewriteRule (.*) index.php [L]

RedirectMatch 301 ^/uploads/users/avatar/$ /images/default-user.jpg

RewriteCond %{REQUEST_URI} uploads
RewriteRule ^uploads/(.*)/(.*)/(.*)$ /api/index.php/media/load?fileKey=$3 [QSA,L]

#force https
#RewriteCond %{HTTP:X-Forwarded-Proto} =http
#RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

http部分已注释掉。任何人都可以帮我这个吗?

1 个答案:

答案 0 :(得分:-1)

尝试以下方法:

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]