LoginSignup
4
3

More than 5 years have passed since last update.

localhost以外をhttpsにリダイレクトさせる.htaccess設定

Posted at

ちょっとしたWEBシステムを作る時に、ローカル環境までhttpsでアクセスできる環境を作るのが面倒。

なので、localhostでアクセスしたときはhttp、それ以外のドメインだとhttpsにリダイレクトする.htaccessの書き方

.htaccess
RewriteEngine on 
RewriteCond %{ENV:HTTPS} !on 
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTP_HOST} !=127.0.0.1
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3