http⇔httpsリダイレクト処理

電脳備忘録

/contactおよび/sp/contactディレクトリにはコンタクトフォームが設置してあるのでhttpsで表示させ、それ以外はhttpで表示させたときの設定。
imgやcss等は共有で使用するのでエラー表示されないように設定しました。

RewriteEngine on
#Rewrite for SSL Page
RewriteCond %{REQUEST_URI} ^/contact/.*$ [OR]
RewriteCond %{REQUEST_URI} ^/sp/contact/.*$
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
#Rewrite for non-SSL Page
RewriteCond %{REQUEST_URI} !(^/contact/.*$)
RewriteCond %{REQUEST_URI} !(^/mt/plugins/MailForm/.*$)
RewriteCond %{REQUEST_URI} !(^/img/.*$)
RewriteCond %{REQUEST_URI} !(^/js/.*$)
RewriteCond %{REQUEST_URI} !(^/css/.*$)
RewriteCond %{REQUEST_URI} !(^/sp/contact/.*$)
RewriteCond %{REQUEST_URI} !(^/sp/common/.*$)
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

動作確認してみましたが、リダイレクト処理がかかってるしファイルが読み込めないなどのエラーも発生しなかったので、たぶん問題ないのかなぁと・・・。

広告

ブログの維持費に充てるでございます・・・。