【问题标题】:Redirect HTTP to HTTPS on AWS Elastic Beanstalk load balancer with additional mod_rewrite rules使用额外的 mod_rewrite 规则将 AWS Elastic Beanstalk 负载均衡器上的 HTTP 重定向到 HTTPS
【发布时间】:2018-01-21 05:37:07
【问题描述】:

我在 AWS Elastic Beanstalk 上有一个 Web 应用程序,并且 SSL 工作正常,但我需要确保所有流量都是 HTTPS。我认为与我们现有的规则或负载均衡器存在冲突。以下是我们 .htaccess 文件中的规则: 重写引擎开启

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 部分被注释掉。谁能帮我解决这个问题?

【问题讨论】:

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


    【解决方案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]
    

    【讨论】:

    • 我试过了。它又给了我 ERR_TOO_MANY_REDIRECTS 东西
    • 你对问题提出的规则是唯一的吗?
    • 是的,但这是运行在后面的服务器和 AWS 负载均衡器。被注释掉的版本是推荐的解决方案。
    猜你喜欢
    • 2017-12-01
    • 2016-11-26
    • 2014-06-18
    • 2015-03-18
    • 2019-07-25
    • 2017-01-07
    • 2017-09-28
    • 2017-02-19
    • 1970-01-01
    相关资源
    最近更新 更多