[mod_rewrite] Apacheでhttps通信を強制する方法

Apacheではmod_rewriteを使用してhttps通信を強制することができる。
「httpd.conf」に以下の記述を追加してapacheを再起動すればOK。

RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]

参考記事

301 Moved Permanently