在表达式引擎重定向循环上强制HTTPS

时间:2014-06-29 02:12:33

标签: .htaccess ssl https load-balancing expressionengine

我正在尝试使用运行表达式引擎的网站的.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>

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

我有同样的情况,这里有一个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]
相关问题