Redirect a Non-Resolving Domain Using Cloudflare

Published on Sunday, September 29th, 2024 | 4 min read

Hero image with the Cloudflare logo.

So, you have a domain that doesn’t point anywhere. No DNS records, no website, nothing. Maybe it’s a domain you bought during a late-night “investment” spree, or it’s simply that forgotten backup domain you keep around “just in case.” Whatever the reason, it’s floating in the digital void but you still want to redirect it somewhere useful. Cloudflare provides customizations and rules set for your domains, from rate limiting, firewall, caching, redirects, and more. Let’s jump right in, this wont take more than a couple of minutes.

Step 1: Add Placeholder DNS Records

First off, let’s get one thing straight: Cloudflare doesn’t just magically handle your redirects. You have a domain with nothing! That’s like telling a mail carrier, “Here, deliver this to nowhere.” So, let’s add some placeholder DNS records.

  1. Log in to Cloudflare and select your domain.

  2. Head over to the DNS tab, on the left side of the page.

  3. Add an A Record (IPv4):

    • Type: A
    • Name: @ (this is the root domain)
    • IPv4 Address: 192.0.2.1

      192.0.2.0/24 - This block range is assigned as “TEST-NET-1” for use in documentation and example code… RFC 5735

    • TTL: Auto
    • Set the Proxy status to Proxied (you’ll recognize it by the little orange cloud).
  4. Add another A Record for the www subdomain:

    • Type: A
    • Name: www
    • IPv4 Address: 192.0.2.1
    • TTL: Auto
    • Proxy status: Proxied.
  5. If you’re feeling fancy and want to use IPv6, go for the AAAA Record:

    • Type: AAAA
    • Name: @ or www.
    • IPv6 Address: 100::
    • TTL: Auto
    • Proxy status: Proxied.

Example of a DNS example settings.

I exported my DNS settings and switched and for the example purposes I swapped out my domain name to example.com. It should look similar to this but with your correct domain names.

;; Domain:     example.com.
;; Exported:   2024-09-29 06:07:59
;;
;; This file is intended for use for informational and archival
;; purposes ONLY and MUST be edited before use on a production
;; DNS server.  In particular, you must:
;;   -- update the SOA record with the correct authoritative name server
;;   -- update the SOA record with the contact e-mail address information
;;   -- update the NS record(s) with the authoritative name servers for this domain.
;;
;; For further information, please consult the BIND documentation
;; located on the following website:
;;
;; http://www.isc.org/
;;
;; And RFC 1035:
;;
;; http://www.ietf.org/rfc/rfc1035.txt
;;
;; Please note that we do NOT offer technical support for any use
;; of this zone data, the BIND name server, or any other third-party
;; DNS software.
;;
;; Use at your own risk.
;; SOA Record
example.com	3600	IN	SOA	server.ns.cloudflare.com. dns.cloudflare.com. 2047925667 10000 2400 604800 3600

;; NS Records
example.com.	86400	IN	NS	server.ns.cloudflare.com.
example.com.	86400	IN	NS	server.ns.cloudflare.com.

;; A Records
example.com.	1	IN	A	192.0.2.1
www.example.com.	1	IN	A	192.0.2.1

Step 2: Create a Redirect Using Cloudflare Page Rules

With the DNS records in place, we can now redirect traffic.

  1. Go to the Rules tab:

    • Open your domain’s Rules tab in Cloudflare.
  2. Create a Page Rule:

    • Click on Create Page Rule to begin the setup.
  3. If… When incoming requests match…

    • Select: All incoming requests (This will ensure the rule applies to all traffic to your domain.)
  4. Configure the Redirect:

    • Type: Static.
    • URL: Destination URL, for example, https://anotherexample.com. This is where you want visitors to be redirected.
    • Code: 301 - Permanent Redirect.
      • A 301 tells browsers and search engines that your domain has moved permanently. It’s like moving houses and notifying the postal service to update your address.
      • A 302 is more like paying 99 cents for a temporary mail forwarding service—not permanent.
  5. Save and Deploy:

    • Click the Save and Deploy button and you are done with all the necessary configurations.

Step 3: Testing the Redirect

Let’s test this out. You will need to wait a couple of minutes for the rules and DNS to propagate. Sometimes it’s fast but assume that it will take a bit.

  1. Open your web browser and type in your domain (e.g., example.com or www.example.com).
  2. If you’re redirected to the destination domain, which in our steps we said it was https://anotherexample.com. Congrats!

Conclusion

So, there you have it. Redirecting a domain with Cloudflare, even when it doesn’t resolve to an actual service, is entirely possible. By setting up placeholder DNS records and creating a 301 redirect, you can point visitors to a primary domain.