.htaccess に保存してサイトのトップに置きます。
<ifModule mod_rewrite.c>
RewriteEngine On
# http でのアクセス
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# https でのアクセス
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.hogehoge\.com$
RewriteRule ^(.*)$ https://hogehoge.com/$1 [R=301,L]
</ifModule>
上の書き方でリダイレクト連続する場合は次のようにも書きます。
# http でのアクセス
RewriteCond %{ENV:HTTPS} !^on$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]