【.htaccess】特定のディレクトリにSSL通信をする

htaccessで特定のディレクトリにSSL通信をする

Apache2.4で.htaccessで特定のディレクトリにSSL通信をします。
ここではadminとcontactディレクトリのみSSLに設定して、
その他のディレクトリはhttp通信とします。

本当は全ページSSL化したほうがセキュリティ的にいいですが、
クライアントの要望により一部だけSSL化したいときに使います。

Rewrite をhtaccessに記述する

adminとcontactディレクトリのみhttps化します。

RewriteEngine on

RewriteCond %{REQUEST_URI} /admin/
RewriteCond %{REQUEST_URI} /contact/
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteCond %{REQUEST_URI} !/admin/
RewriteCond %{REQUEST_URI} !/contact/
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

 

0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
ak

ありがとうございます。おかげさまでうまくいきました。

1
0
Would love your thoughts, please comment.x
()
x