Windowsソフト、iPhoneアプリ、ゲーム音楽素材の「Meteoric Stream」 -> 資料室 -> サーバー関連 -> 【.htaccess】httpアクセスをhttpsに強制リダイレクトで、特定のファイルやディレクトリを除外する方法
【.htaccess】httpアクセスをhttpsに強制リダイレクトで、特定のファイルやディレクトリを除外する方法
.htacessで、http://〜のURLを、https://に強制的にリダイレクトさせる処理なのですが、実際は、画像やRSS、cssなどについては、リダイレクトさせずに、http、httpsどちらからでもアクセスできるようにしておきたいので、特定のディレクトリやファイルを除外して、それ以外を強制リダイレクトさせたい、というサンプルです。
・・・文章にすると、意味不明ですな(笑)
※「\」は、半角のバックスラッシュに置き換えてください。
・・・文章にすると、意味不明ですな(笑)
※「\」は、半角のバックスラッシュに置き換えてください。
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !(^/hoge/)
RewriteCond %{REQUEST_URI} !\.css$
RewriteCond %{REQUEST_URI} !\.js$
RewriteCond %{REQUEST_URI} !\.jpg$
RewriteCond %{REQUEST_URI} !\.gif$
RewriteCond %{REQUEST_URI} !\.png$
RewriteCond %{REQUEST_URI} !\.xml$
RewriteCond %{REQUEST_URI} !\.rss$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !(^/hoge/)
RewriteCond %{REQUEST_URI} !\.css$
RewriteCond %{REQUEST_URI} !\.js$
RewriteCond %{REQUEST_URI} !\.jpg$
RewriteCond %{REQUEST_URI} !\.gif$
RewriteCond %{REQUEST_URI} !\.png$
RewriteCond %{REQUEST_URI} !\.xml$
RewriteCond %{REQUEST_URI} !\.rss$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
この記事の最終更新日:2018/02/19
最初に記事を書いた日:2018/02/19
インターネット黎明期から運営している生きる化石、Meteoric Streamへようこそ!