CakePHP如何在遠振的主機上設定強制全站啟用SSL

Sebastian Hsu
Aug 23, 2017 · 2 min read

記錄如何在cPanel更改CakePHP的.htaccess,讓全站強制從http轉到https

  1. 開啟文件管理器之後進到「public_html」
  2. 點選右上角的「設置」(不熟cPanel的真的會卡在這 XD)
  3. 勾選「 显示隐藏文件(dotfiles)」

接下來就把.htaccess改成這樣就好了

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# FORCE SSL REDIRECTION
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade