我想将流量重定向到HTTPS
来自myawesomesite.com
它重定向到https://myawesomesite.com
,来自http(s)://www.myawesomesite.com
,根据来电,它会转到HTTP
或HTTPS
。
出了什么问题? 我的虚拟主机文件是:
<VirtualHost *:80>
DocumentRoot /var/www/myawesomesite/public
ServerName myawesomesite.com
ServerAlias www.myawesomesite.com
<Directory "/var/www/myawesomesite/public/">
AllowOverride All
Options FollowSymLinks
</Directory>
ErrorLog /var/log/apache2/myawesomesite-error_log
RewriteEngine On
RewriteCond %{SERVER_NAME} ="myawesomesite.com" [OR]
RewriteCond %{SERVER_NAME} ="www.myawesomesite.com"
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI}
</VirtualHost>
答案 0 :(得分:1)
这是通过重写功能强制SSL的正确方法:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
当然,删除您当前的代码。享受!
更新
你也可以这样做更好:
<virtualhost *:80="">
ServerName www.example.com
Redirect / https://www.example.com/
</virtualhost>