【问题标题】:Forcing HTTPS on expression engine redirect loop在表达式引擎重定向循环上强制使用 HTTPS
【发布时间】:2014-08-19 18:56:31
【问题描述】:

我正在尝试使用运行表达式引擎的站点的 .htaccess 来强制使用 HTTPS。 截至目前,您可以使用 https:// 访问该站点,但是当我添加任何这些规则时,它会显示重定向循环。

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mydomain.com/$1 [R,L]

还有这个花哨的

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

我还尝试重新排列每个规则的所有规则,所以我很确定这与不应该匹配的条件有关。

我还阅读了一些关于负载平衡器将事物重定向到 .htaccess 的内容 从这里: .htaccess redirect loop when trying to add forced HTTPS rule (Amazon Elastic Beanstalk) 和这里:https://serverfault.com/questions/283525/force-ssl-on-one-page-via-htaccess-without-looping

我认为我的客户正在使用 inmotion 托管,但我无权访问负载平衡器设置,因此我想确定这是问题所在。

这里是整个 htaccess。我删除了一些默认表达式引擎的东西,但在我这样做之前它也无法正常工作。

<IfModule mod_rewrite.c>
# Enable Rewrite Engine
# ------------------------------
RewriteEngine On
RewriteBase /

# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

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

# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteCond %{THE_REQUEST} ^GET
RewriteRule ^index\.php(.+) $1 [R=301,L]

# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|images|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

(我已将它们禁用,因为该网站已上线)

【问题讨论】:

    标签: .htaccess ssl https load-balancing expressionengine


    【解决方案1】:

    您最好在 EE Stack Overflow site 上发帖。或者搜索一下,因为有一些与 https 和 .htaccess 相关的答案

    这是我之前回复的帖子,您可能想尝试一下: https://expressionengine.stackexchange.com/questions/7601/adding-a-htaccess-redirect-to-https-that-plays-nicely-with-existing-ee-htacces/7659#7659

    如果此条件不起作用:

    RewriteCond %{SERVER_PORT} !^443$
    

    试试这个:

    RewriteCond %{HTTPS} !=on
    

    而不是这个:

    RewriteCond %{HTTPS} off
    

    【讨论】:

      【解决方案2】:

      我也遇到过同样的情况,这就是我在 EE3 网站上遇到的情况:

      #non-www to www
      RewriteCond %{HTTP_HOST} !^www\.domainname\.co.uk$
      RewriteRule (.*) https://www.domainname.co.uk/$1 [R=301,L]
      
      # Force HTTPS
      RewriteCond %{HTTPS} !=on
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
      
      # Removes index.php from ExpressionEngine URLs
      RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
      RewriteCond %{REQUEST_URI} !/system/.* [NC]
      RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
      

      【讨论】:

        猜你喜欢
        • 2014-09-29
        • 2016-03-11
        • 2011-11-01
        • 2013-11-14
        • 1970-01-01
        • 1970-01-01
        • 2016-12-27
        • 2013-02-11
        • 2015-06-30
        相关资源
        最近更新 更多