2
0

More than 1 year has passed since last update.

Cloudflare "Always Use HTTPS" を Redirect Rules で書く

Last updated at Posted at 2023-01-20

Always Use HTTPS とは

対象ドメイン内ですべての http リクエストを https に 301 リダイレクトする設定です。

image-20230121012552757

Ridirect Rules で書く

Redirect Rules を使えば、従来の Page Rules より柔軟で Dynamic な挙動を実現できます。

今回の "Always Use HTTPS " を Redirect Rules で書くと以下のようになります。

ここをスタートポイントとして、除外したい条件やより特定したい条件を追加すると便利です。

image-20230121013008782

確認

以下のように想定通りの挙動になったことが確認できます。

% curl -v "http://www.example.com/articles/index?section=539061&expand=comments"
*   Trying 2606:4700::6812:9e2:80...
* Connected to www.example.com (2606:4700::6812:9e2) port 80 (#0)
> GET /articles/index?section=539061&expand=comments HTTP/1.1
> Host: www.example.com
> User-Agent: curl/7.82.0-DEV
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Date: Fri, 20 Jan 2023 16:16:14 GMT
< Transfer-Encoding: chunked
< Connection: keep-alive
< Cache-Control: max-age=3600
< Expires: Fri, 20 Jan 2023 17:16:14 GMT
< Location: https://www.example.com/articles/index?section=539061&expand=comments
< Server: cloudflare
< CF-RAY: 78c91d09fa57ef81-NRT
< 
* Connection #0 to host www.example.com left intact
2
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
2
0