120
128

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

apacheでhttpへのアクセスをhttpsへ自動リダイレクトする

Posted at

sslの設定などの説明は省略します。

/etc/httpd/conf/conf.d/rewrite.confを設定

今回は/etc/httpd/conf/conf.d以下にリダイレクト処理だけを書く設定ファイルを用意しました。/etc/httpd/conf/httpd.confに直接書いても構いません (ただしモジュールのロードの後に書く必要があります。)

mod_rewriteの設定

<ifModule mod_rewrite.c>
      RewriteEngine On
      LogLevel alert rewrite:trace3
      RewriteCond %{HTTPS} off
      RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</ifModule>

RewriteRuleは書き換えのルール、
RewriteCondRewriteRuleを適用するかを判断するための条件です。今回はHTTPSがOffの場合、つまりhttp通信の場合にルールを適用させます。

※注意
RewriteLog, RewriteLogLevelの設定はapache2.4から削除されました。古い記事を参考にするとSyntaxErrorになりますので気をつけましょう。

120
128
1

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
120
128

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?