2019年1月27日 星期日

從頭開始,一步一步架起低成本網站【第4章~強制使用https網址】

URL Rewrite機制

將所有http路徑導向到https路徑

首先啟用apache2中的rewrite模組

a2enmod rewrite


接著在網站的根目錄下新增一個.htaccess檔案,並增加以下內容

#避免直接存取目錄
Options -Indexes
#rewrite
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]












存檔後檢查讀取權限

chmod 755 .htaccess


最後測試用http輸入網址後是否有正常導向到https

熱門文章