Cloudflare Tutorial: Setting Up a 301 Permanent Redirect for a Domain Name

💡 Preliminary Notes: With this tutorial, you'll learn how to automatically redirect users to a specified URL when they visit your domain.
⚠️ Important Reminder: After changing a domain name's DNS servers, it takes some time for the changes to take effect (typically anywhere from several tens of minutes to 24 hours, and up to 48 hours). Please be patient after completing the configuration,Don't test repeatedly.

 

Step 1: Add a domain to Cloudflare

  1. Log in to the Cloudflare dashboard and click on the left-hand menu's Domians(Domain Name) → Overview(Overview), then click Add site(Add a site).
  2. Enter your own domain name and click "Continue."
  3. Select Free(Free) Plan—after confirmation, proceed to the next step.

Add a Domain to Cloudflare

 

Step 2: Add 2 DNS records (the Orange Proxy must be enabled)

Key Points: The IP address entered here is a sample virtual address,You do not need to replace this with your own server's IP address.

Add the following two lines A Record

Type Host Records Recorded values Agent Status
A @ 192.0.2.1 Enable Orange Cloud (Proxy)
A www 192.0.2.1 Enable Orange Cloud (Proxy)

🚨 Tips for Avoiding Pitfalls: Cloud iconMust be displayed in orange(Proxy is enabled). If this option is grayed out, it means the proxy is not enabled, and the 301 redirect feature will not work properly.

Once you've finished adding the information, click "Continue to the Next Step."

 

Step 3: Change the DNS servers with your domain registrar

Go to the platform where you purchased your domain (such as Alibaba Cloud, Tencent Cloud, GoDaddy, etc.) and locate the domain's DNS Management Page:

  1. Delete the current default DNS server addresses.
  2. Replace them with the following two sets of addresses assigned to you by Cloudflare (these are examples; please use the addresses displayed in your Cloudflare dashboard):
    • isla.ns.cloudflare.com
    • lloyd.ns.cloudflare.com

Save your changes and wait for the DNS changes to take effect worldwide.

📌 Example (Alibaba Cloud): Domains & Websites → Domain List → Click the corresponding domain → DNS Management → Change DNS Servers.

Changing the DNS Servers of Your Domain Name Provider on Alibaba Cloud

 

Step 4: Create a 301 Redirect Rule

  1. Return to the Cloudflare dashboard and click the menu Rules(Rules) → Overview(Overview) →Create rule(Create Rule) → Then click Redirect Rules(Redirect Rules)
  2. Give the rule any name you like (for example, “301 Redirect”).
  3. Match Criteria Select Custom filter expression(Custom filter expression).

Create a 301 Redirect Rule

 

Two transition effects—please choose the one that best suits your needs.Choose one of the two, Do not set both at the same time

There are two transition effects; please choose one based on your needs—do not set both at the same time.👉 Option 1: Redirect to the home page only (recommended for beginners)

Effect: Only when accessing the domain's homepage (i.e., the root path) /) the page will redirect; when accessing other subpages, the page loads normally and does not redirect.

Steps for Configuring the Graphical User Interface

  1. Add Condition ①:Hostname equals Your Domain Name(without www, for example example.com
  2. Click Or Additional Condition ②:Hostname equals Your Domain Name(with www, for example www.example.com
  3. Add another condition ③:URI Path equals /

 

👉 Option 2: Redirect all pages

Effect: Whether you visit the homepage or any subpage, you will be automatically redirected to the target URL.

Steps for Configuring the Graphical User Interface

  1. Add Condition ①:Hostname equals Your Domain Name(without www
  2. Click Or Additional Condition ②:Hostname equals Your Domain Name(with www

💡 Note: Regular users are advised to simply check the boxes in the graphical interface shown above; advanced users can also click “Edit Expression” to write code directly.

 

Set Redirect Behavior (The following settings apply to both options)

Set Redirect Behavior

  • URL Type: Select Static(Static) — ❌ Don'tSelect "Dynamic"
    A simple explanation: "Static" means that all requests are redirected toThe same oneA static URL (the one you enter below); a dynamic URL means that the destination address is automatically generated based on different requests. Regular users don't need this feature—selecting "static" is sufficient.
  • Destination Address (URL): Enter the full URL you want to navigate to, for example https://www.meowtool.com/miaonav
  • Status Code: Select 301 - Permanent Redirect(Permanent Redirect)
  • Preserve query stringClose(i.e., without the original URL parameters)
  • Rule Priority (Place at): First(If “First” is selected for the redirect rule, this rule will be executed first; if “Last” is selected, it will be placed at the end of all existing rules and executed last.)

Once all settings are complete, click Save(Save). Once the DNS changes take effect, you can test whether the site is accessible.

Frequently Asked Questions (FAQ)

1.按教程操作后访问域名没有跳转,是什么原因?

最可能的原因是 DNS 尚未全球生效(最长需 48 小时)。请先确认:域名服务商处的 DNS 是否已成功修改为 Cloudflare 分配的两组地址;Cloudflare 后台域名状态是否为 Active;两条 A 记录的云朵图标是否均为橙色。如以上均确认,建议等待 1~2 小时后再测试,不要频繁反复修改

2.两条 A 记录里的 192.0.2.1 需要换成我自己的服务器 IP 吗?

不需要。 该 IP 仅为示例虚拟地址,开启橙色代理后 Cloudflare 会接管流量,实际回源 IP 由 Cloudflare 决定。请保持原样即可。

3.方案 1(仅跳转首页)和方案 2(全部跳转)可以同时启用吗?

不可以。 两者互斥,同时设置会导致规则冲突或跳转行为异常。请根据实际需求只选择其中一种配置。

4.跳转规则保存后多久生效?

规则在 Cloudflare 端即时生效,但最终访问效果受 DNS 解析进度影响。DNS 完全生效后(通常几十分钟到 24 小时),跳转立即工作。生效前请勿反复开关规则或修改 DNS。

5.我想临时关闭跳转,该怎么做?

回到 Cloudflare 后台 Rules → Overview,找到创建的跳转规则,将开关设为 Disable(关闭),或直接删除该规则。关闭后原域名恢复正常访问(无跳转行为)。

6.域名在 Cloudflare 购买的,还需要修改 DNS 服务器吗?

不需要。 Cloudflare 注册的域名 DNS 默认由 Cloudflare 管理,直接跳过教程第 3 步,从第 4 步开始配置跳转规则即可。

Previous Article A 300-DVD Set of Chinese Games That Brings Back Memories
August 2026
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
Loading...
List of Articles
1 The Funny Little Orange
The Funny Little Orange
2
What Is Success? Perhaps We Need to Live in the Moment
What Is Success? Perhaps We Need to Live in the Moment
3
Image Data Eraser
Image Data Eraser
4
How to Deploy a Simple Static Website Using GitHub
How to Deploy a Simple Static Website Using GitHub
5
Functionality Comparison of Domestic and International AI Search Tools: Mitta AI vs. Perplexity
Functionality Comparison of Domestic and International AI Search Tools: Mitta AI vs. Perplexity