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.
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
- Setting up your (sub)domain
Configure a
CNAME
record for your chosen subdomain (this works with the root domain too!), with a value ofalias.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 of45.55.72.95
. - Configuring redirection
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 yourCNAME
orA
record for the name value of the configurationTXT
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: redirectyoursite.com/blog/*
toblog.yoursite.com/*
,yoursite.com/forum/*
toforum.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.