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



我试图使用运行表达式引擎的站点的.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]

,我也试着重新安排了它们每个的所有规则,所以我很确定这与它们不应该匹配的条件有关。

我也读过一些关于负载均衡器重定向的东西counter .htaccess从这里开始:.htaccess重定向循环时,试图添加强制HTTPS规则(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>

你最好在EE Stack Overflow网站上发帖。或者搜索一下有一些关于https和。htaccess的答案

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

如果这个条件不成立:

RewriteCond %{SERVER_PORT} !^443$

试试这个:

RewriteCond %{HTTPS} !=on

代替这个:

RewriteCond %{HTTPS} off

我也遇到过同样的情况,下面是我在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]

最新更新