Apache .htaccess rewriteでhttpsアクセスを強制する
ブログ » Apache .htaccess rewriteでhttpsアクセスを強制する
22 Apr 2014 14:01公開
Apache .htaccess rewriteでhttpsアクセスを強制することが可能である。
.htaccessでホスティングサービスでできる設定
.htaccessだけで、パスワードなど制限はかけられる。
Basic password ベースのアクセス
AuthUserFile /home/<user>/.htpasswd AuthType Basic AuthName "My Secret Folder" Require valid-user
リライトエンジンで強制httpsアクセス
大体のホスティングサービスは共有型SSL(https)を提供している。しかし、かなりの金額を出さない限り(Private SSL + Dedicated IP)、プライベート型SSLがもらえない。また、共有型のSSLは自分のドメインと異なるドメイン名を登録しているため、自分のドメイン配下のコンテンツをSSLで見せることができない。リライトエンジンを利用すると、簡単に全てのアクセスを共有型のSSLコンテンツにRedirectすることができる。
RewriteEngine on RewriteCond %{HTTP_HOST} subdomain.<my domain> RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://<hosting service domain name>/~<user>/host%{REQUEST_URI} [R,L] #RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L] RewriteCond %{HTTP_HOST} <my domain> RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://<hosting service domain name>/~<user>%{REQUEST_URI} [R,L] #RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L] RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L] #RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
レーティング
コメント