一部のページだけSSLで通信させたいとき、.htaccessでRewriteするのが楽でした。
.htaccessでのRewriteはFollowSymLinksが有効になっていないといけません。
1 2 3 4 5 6 |
<Directory "/var/www/test"> Options FollowSymLinks AllowOverride All Order Allow,Deny Allow from All </Directory> |
該当ディレクトリの.htaccessにルールを記入します。
1 2 3 4 5 6 |
RewriteEngine on RewriteCond %{REQUEST_URI} .*/$ [OR] RewriteCond %{REQUEST_URI} .*/index.php$ [OR] RewriteCond %{REQUEST_URI} .*/critical.html$ RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L] |
上記設定は、指定する3つのURIのいずれかに該当するHTTPリクエストに対して、httpsに書き換えるというルールです。