將http連線改為https

免費主機申請了免費SSL使用,要讓原本的http(port 80)連線,改走https(port 443),查了一下簡單的做法,可以修改.htaccess來將http改向https連線:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yoururl.com.tw/$1 [R,L]

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

留言