Cloudflare's current dashboard no longer relies on Page Rules for this kind of redirect. The replacement is Redirect Rules, and for a simple host-to-host 301 it takes just a few fields.

Go to Rules -> Redirect Rules -> Create rule. The configuration below redirects a subdomain to the main domain while preserving the request path.

Cloudflare redirect rule configuration

  • Rule name: use any descriptive name.
  • When incoming requests match: choose Custom filter expression.
  • Field: Hostname
  • Operator: equals
  • Value: the host you want to redirect, e.g. blog.0x8.net
  • URL redirect: type Dynamic, expression concat("https://0x8.net/", http.request.uri.path), status code 301

Deploy the rule when done. To check it, send a HEAD request with curl -I:

$ curl -I blog.0x8.net/etc
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0   167    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0HTTP/1.1 301 Moved Permanently
Date: Wed, 05 Jun 2024 14:16:48 GMT
Content-Type: text/html
Content-Length: 167
Connection: keep-alive
Cache-Control: max-age=3600
Expires: Wed, 05 Jun 2024 15:16:48 GMT
Location: https://0x8.net/etc
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=j9lIWeQVswYKqqidSUDzUvEr8XGf9R8E04whnlBIYvRcDSxArK7sQseo1lRbYUR2nRQdYiJ8vjQla3rp%2FC33QRQtFCidEtcNWxja0jraL20cgH9TOoXTlThy"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
X-Content-Type-Options: nosniff
Server: cloudflare
CF-RAY: 88f0c857e8347708-LHR

The response shows that blog.0x8.net/etc is being redirected to https://0x8.net/etc with a 301.

The older Page Rules approach is no longer valid. It used to be configured under Rules -> Page Rules in the domain dashboard. That setup looked like this:

- URL:  aosp.me/*
- 选取设置 : 转发 URL
- 选择状态代码: 301-永久重定向
- 输入目标 URL: https://0x8.net/$1

After saving and deploying, the Page Rule would take effect—but this method has been retired, so use Redirect Rules instead.