我正在尝试将所有流量从http定向到https:
www.example.com-> https://www.example.com
example.com-> https://example.com
服务器是在Ubuntu 16.04(setup tutorial used)上运行LAMP的AWS EC2实例。
由Let's Encrypt为example.com和www.example.com(tutorial used)生成SSL证书。
我已经经历了十几个SO答案和其他教程,并且.htaccess示例代码都没有为我提供帮助。以下是我尝试过但没有成功的一些清单(我尝试过通过SFTP上传文件和通过nano进行SSH编辑):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]
,
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
,
RewriteEngine On
# https/http www -> https non-www
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# http non-www -> https non-www
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
,
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
,
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
,
RewriteEngine On
RewriteBase /
https://www.primesoft.in
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.%{SERVER_NAME}/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://www.%{SERVER_NAME}/$1 [R=301,L]
任何帮助将不胜感激。
答案 0 :(得分:0)
经过更多研究,结果表明Apache默认情况下已关闭.htaccess。这个答案解决了它: .htaccess not being loaded in Ubuntu 14.04 (Apache 2.4.7)