0
0

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 3 years have passed since last update.

http/httpsとwwwありなしのリダイレクトとSSLのドメイン適用範囲でハマった話

Last updated at Posted at 2021-06-10

SSL証明書対応+www付きのドメインにリダイレクトさせる設定をしていたところ
何故かwwwが付かず、且つSSLが適用されずエラーが発生する問題に遭遇
スクリーンショット 2021-06-10 19.57.45.png

設定を確認する

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^chinjaolose\.co\.jp$
RewriteRule ^(.*)$ https://www.chinjaolose.co.jp/$1 [R=301,L]

合ってるのではないのか
:closed_lock_with_key: マークをクリックしてSSL証明書を確認

サブジェクト名:*.chinjaolose.co.jp

「*」って何〜?

調べたところSSLの適用範囲が chinjaolose.co.jp のサブドメインに対してのみらしい。
なのでネイキッドドメイン「chinjaolose.co.jp」に対してはSSLが無効(というかなりすましみたいな扱い)になってしまうようである。

改めて確認してみる

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^chinjaolose\.co\.jp$
RewriteRule ^(.*)$ https://www.chinjaolose.co.jp/$1 [R=301,L]

http://chinjaolose.co.jp でアクセスした場合のリダイレクトの順番としては

1.httpにsがついてない
 →sを付けてリダイレクト(https://chinjaolose.co.jp)

2.ホスト名がchinjaolose.co.jpである
 →wwwを付けてリダイレクト

となるのだが、1の段階でchinjaolose.co.jpにはSSLが適用されないので
リダイレクトが中断してエラーになってしまうようである。

対応策

灯台なんとやらでこうすれば良かった

# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# RewriteCond %{HTTP_HOST} ^chinjaolose\.co\.jp$
# RewriteRule ^(.*)$ https://www.chinjaolose.co.jp/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^chinjaolose\.co\.jp
RewriteRule ^(.*) https://www.chinjaolose.co.jp/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

SSLが有効なドメインに対してリダイレクトを掛けた後にhttps を付けてあげる

逆にしただけ

終わり。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?