Setup type "yourdomain.com" tự động trỏ về "www.yourdomain.com"
1. Tạo tài khoản Cloudflare
Vào https://dash.cloudflare.com, đăng ký (miễn phí).
Sau khi đăng nhập → bấm Add a site → nhập domain
yourdomain.com.
2. Quét DNS từ PA sang Cloudflare
Cloudflare sẽ tự quét các bản ghi DNS hiện tại từ PA.
Kiểm tra lại các record (MX, TXT, email… nếu có) → đảm bảo đủ.
Xong bấm Continue.
3. Trỏ Nameserver từ PA sang Cloudflare
Cloudflare sẽ cung cấp cho bạn 2 nameserver, ví dụ:
amy.ns.cloudflare.com tom.ns.cloudflare.comĐăng nhập portal.pa.vn → Quản lý tên miền → Nameserver.
Đổi sang nameserver của Cloudflare và xoá hết các nameserve mặc định đi. Bước này không cần nhập ipv4 và ipv6 cho 2 nameserve mới
Lưu lại. (Quá trình này mất từ 15 phút đến vài giờ để cập nhật).
4. Thêm record cho GitBook trong Cloudflare
Sau khi domain đã “qua” Cloudflare:
Vào DNS → Records.
Tạo record cho domain gốc:
Type: CNAME Name: @ Target: 7c85d8d882-hosting.gitbook.io Proxy status: DNS only (màu xám)Tạo record cho www (để tương thích):
Type: CNAME Name: www Target: 7c85d8d882-hosting.gitbook.io Proxy status: DNS only
👉 Cloudflare hỗ trợ CNAME Flattening, nên domain gốc sẽ hoạt động giống như www luôn.
5. Bật SSL/TLS
Vào SSL/TLS trong Cloudflare → chọn chế độ Full (hoặc Flexible nếu GitBook không hỗ trợ HTTPS mặc định, nhưng GitBook có rồi → chọn Full).
SSL/TLS, Chọn tab Edge Certificates, Kéo xuống dưới, bật công tắc Always Use HTTPS và Automatic HTTPS Rewrites → ON.
Từ giờ mọi request HTTP (http://yourdomain.com) sẽ tự động chuyển thành HTTPS (https://yourdomain.com).
6. Redirect domain gốc ↔ www trong Cloudflare
Ví dụ: bạn muốn mọi truy cập vào yourdomain.com tự động chuyển sang www.yourdomain.com. (Ngược lại cũng làm tương tự).
1. Tạo Forwarding Rule (cách mới, thay cho Page Rules cũ)
Vào Cloudflare dashboard → chọn domain.
Ở menu trái → chọn Rules → Redirect Rules.
Bấm Create rule.
2. Cấu hình rule
Đặt tên rule:
Redirect non-www → www.Ở phần If... (condition):
Field:
HostnameOperator:
equalsValue:
yourdomain.com
Ở phần Then... (action):
Chọn Static Redirect
Redirect type:
301 Permanent RedirectDestination URL:
https://www.yourdomain.com/$1
Bắt buộc phải có $1 để giữ nguyên đường dẫn
Gõ
http://yourdomain.com/blog/abc→ sẽ thànhhttps://www.yourdomain.com/blog/abc.
Bấm Deploy rule.
Last updated