【问题标题】:Force redirect http to https on Elastic Beanstalk [closed]在 Elastic Beanstalk 上强制将 http 重定向到 https [关闭]
【发布时间】:2013-03-30 20:35:20
【问题描述】:

为了在 AWS Elastic Beanstalk php 应用程序上将 http 重定向到 https,我在 .htaccess 文件上使用了重写规则。

我的问题是我的规则适用于指向文件的 url,但不适用于根域,例如:

http://www.testdomain.com/index.php => redirects OK to => https://www.testdomain.com/index.php

但是

http://www.testdomain.com  does not redirect to https://www.testdomain.com

我的规则:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} !^/status$ 
RewriteCond %{REQUEST_URI} !^/version$ 
RewriteCond %{REQUEST_URI} !^/_hostmanager/ 
RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

感谢您的帮助!

【问题讨论】:

    标签: apache .htaccess mod-rewrite https amazon-elastic-beanstalk


    【解决方案1】:

    regular expression . 至少需要一个字符。如果要匹配任何 URL 路径,包括空的 URL 路径,请使用 ^^.*$

    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
    

    您也可以使用%{HTTPS} 来测试 SSL 连接

    RewriteCond %{HTTPS} off
    

    【讨论】:

      猜你喜欢
      • 2016-06-19
      • 2017-02-27
      • 2018-01-01
      • 2019-09-21
      • 2021-02-23
      • 2018-02-16
      • 2018-01-07
      • 2018-09-30
      • 2017-02-04
      相关资源
      最近更新 更多