.htaccess : http → https の転送

icon Web Server

httpアクセスを制限し,httpsに転送したい場合がある.その場合,.htaccessを次のように設定する.

# httpへのアクセスをhttpsに強制転送
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
</IfModule>

<IfModule>はなくても大丈夫だが,念のため.

タイトルとURLをコピーしました