Apache .httpaccessでhttpsのみに制限

ブログ » Apache .httpaccessでhttpsのみに制限

13 Apr 2014 01:28公開

Apache .httpaccessでhttpsのみに制限

===.htaccessでホスティングサービスでできる設定===

.htaccessだけで、パスワードなど制限はかけられる。

=== Basic password ベースのアクセス ===
<pre>
<nowiki>
AuthUserFile /home/<user>/.htpasswd
AuthType Basic
AuthName "My Secret Folder"
Require valid-user
</nowiki>
</pre>

===リライトエンジンで強制httpsアクセス===
大体のホスティングサービスは共有型SSL(https)を提供している。しかし、かなりの金額を出さない限り(Private SSL + Dedicated IP)、プライベート型SSLがもらえない。また、共有型のSSLは自分のドメインと異なるドメイン名を登録しているため、自分のドメイン配下のコンテンツをSSLで見せることができない。リライトエンジンを利用すると、簡単に全てのアクセスを共有型のSSLコンテンツにRedirectすることができる。
<pre>
<nowiki>
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]
</nowiki>
</pre>

レーティング

rating: 0+x

コメント

Add a New Comment