OrzMiku

Dzの窝

生活明朗,万物可爱。
github
bilibili
modrinth
email

Using CloudFlare Redirect Rules to solve xLog multiple domain binding.

Someone has already written a tutorial on using CloudFlare's domain redirection to accomplish this. Here are two articles:

Implementing Multiple Domain Binding for xlog
Solutions for xlog's Lack of Support for Multiple Domain Addition

These two tutorials, one uses CloudFlare Page Rules to implement, and the other directly uses CloudFlare Pages for redirection.
However, CloudFlare actually has Redirect Rules specifically for redirection rules, but there is relatively little information online, especially regarding dynamic redirection expressions.

Here is an example usage, the goal is to redirect www.miku.show to miku.show, while preserving the path and query string.

Redirect Rules Rule#

  • Rule name: Whatever
  • When incoming requests match: Custom filter expression
  • Then
    • Type: Dynamic
    • Expression: concat("https://", "miku.show", http.request.uri)
    • Status code: 301
  • Preserve query string: Not selected, because the query string is already included in http.request.uri

Then save the rule.

image

Set Proxy#

Although the redirection rule has been set, www.miku.show cannot currently be redirected to miku.show. You need to route the traffic of www.miku.show through CloudFlare's Proxy (not sure if my description is accurate).

Go to DNS resolution and set an A record for www, the value can be filled in randomly, I filled in 1.1.1.1 here, this value doesn't have much impact. But be sure to enable Proxy (turn on the orange cloud).

After adding the resolution, the redirection will work normally. Now:

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.