1.前往/etc/apache2/目錄,打開httpd.conf文件
2.將文件中有關rewrite的注釋去掉
3.文件中在Directory里, 注釋掉AllowOverride none,改成AllowOverride All
并添加
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI}
4.重啟Apache
sudo apachectl restart
測試~
自動跳轉https