DEV Community

Cover image for Forwarding domains without a server with Cloudflare
Jérôme Gamez
Jérôme Gamez

Posted on • Updated on

Forwarding domains without a server with Cloudflare

Photo by zhu bing, sourced from the Cloudflare forums

Imagine you've just bought a new domain for your next side project, haven't got a website for it yet but don't want it to point to the void as well. My usual approach to this in the past was this:

  • Set up the A record of the domain to point to the IP address of my main website.
  • Update the webserver configuration for that site to listen to the new domain.
  • Once the side project is ready, revert the settings and update the A record with a new IP address.

Although this is easy enough, it still requires updating an unrelated site, and what if you don't have an existing site to use as a temporary placeholder?

This was the case when I wanted to redirect my (super old) domain jerome-gamez.de to my current gamez.name. I was already on my VPS to update the configuration when I started to wonder if there was a simpler solution - I think I found one using Cloudflare DNS and Page Rules, and I'd like to share it with you today.


If you haven't already, create an account at Cloudflare (it's free), add your site and point your domain's NS records to the nameservers named on your site's dashboard.

Set up DNS

On the DNS dashboard, enter the following entries:

Type Name Value TTL Proxy status
A @ 192.0.2.1 Automatic enabled
A www 192.0.2.1 Automatic enabled

I'm not sure if the www entry is really needed - I created it to be sure, and it at least didn't break anything

Cloudflare DNS Settings

Set up a page rule

On the Page Rules dashboard, create a new page rule:

URL pattern Setting Value
*your-domain.tld/* Forwarding URL your-target.tld

In case of a temporary forward, use 302 as the status, 301 otherwise.

Cloudflare Page Rule

Wait

Most of the time, the process of propagating the settings is a matter of only a couple of minutes, but it took more in some cases. You can check the current progress on whatsmydns.net.

Once this is done, your domain (and any path on it) should redirect to the target configured in the page rule.

Top comments (2)

Collapse
 
dpaine20 profile image
David Paine20

Great article.
No doubt, DNS changes take time to propagate to all the other DNS servers in the world.
With over 100+ public servers available to check live propagation updates. I think
dnschecker.org/
give you a more detailed propagation results as compared to whatsmydns.net. You must check it out as well.

Collapse
 
yilmazer profile image
Yılmaz

Jérôme Gamez thanks!! I used 1.1.1.1 DNS, great share!