The top resource for frugal webmasters

August 27, 2020

Sometimes, you may want to redirect an entire domain. This normally entails setting up "URL forwarding" with your registrar or configuring NS or A records to point to a server where you can configure the redirections yourself. Fortunately, there's a more efficient way of doing this.

Photo of a street sign

This website has partnerships with some of the companies linked to in this article. When you click those links, the operator of this site may recieve a commission. These partnerships support the site so we can keep bringing you the best answers to your questions.

Most, if not all, domain registrars provide a domain redirection service, often in the form of whole domain to single URL redirection with choice of a few status codes. This is a fairly inflexible system. Some DNS services (like ClouDNS and Cloudflare) provide similar functionality, but not all.

Even if your DNS service does provide this function, a github user by the name of holic has a project going that may interest you. Acting as a proof of concept, it is called redirect.name and allows a level of customization approaching that of .htaccess redirects. The service has been running free for public use the last four or five years. It works by retrieving the desired redirection path from a programmatically determined TXT record on the domain zone. It requries no sign up, and is deployed by configuring a CNAME record pointing to alias.redirect.name.

Setting up redirect.name with Cloudflare

  1. Setting up your (sub)domain
    Cloudflare administration panel, add a new CNAME record

    Configure a CNAME record for your chosen subdomain (this works with the root domain too!), with a value of alias.redirect.name. For Cloudflare, there is no point in orange clouding this record, so select DNS only. Alternatively you can set an A record with a value of 45.55.72.95.

  2. Configuring redirection
    Cloudflare administration panel, add a new TXT record

    Then set up your chosen style of redirection. As per the configuration above, people/crawlers will be redirected from the redirectme domain back to my main site, preserving the requested path (note that you need to prepend _redirect. to the name value of your CNAME or A record for the name value of the configuration TXT record). The syntax for configuring is plain english, and the service supports multiple configuration commands. If you've migrated from a folder structure to multiple subdomains this could be useful, for example: redirect yoursite.com/blog/* to blog.yoursite.com/*, yoursite.com/forum/* to forum.yoursite.com/* and so forth.

The service supports a number of configurations, and I've only presented one, so you'll want to head over to redirect.name to check them all out in detail. Although this is a quick and easy method of redirecting from the DNS level, you would probably want to avoid using this for any kind of paid web design/development, or at least host your own.

Sherman Caine

Sherman is a professional full-stack web developer living in Toronto, Canada, who has been working on websites in one form or another for over 15 years.