<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Website - Websites | Derek Armstrong — Software Engineer · AI · Infrastructure</title><link>https://derekarmstrong.dev/tags/website---websites/</link><atom:link href="https://derekarmstrong.dev/tags/website---websites/index.xml" rel="self" type="application/rss+xml"/><description>Website - Websites</description><generator>Hugo Blox Builder (https://hugoblox.com)</generator><language>en-us</language><lastBuildDate>Wed, 28 Aug 2024 00:00:00 +0000</lastBuildDate><image><url>https://derekarmstrong.dev/media/sharing.png</url><title>Website - Websites</title><link>https://derekarmstrong.dev/tags/website---websites/</link></image><item><title>Redirecting Root Domain with Cloudflare</title><link>https://derekarmstrong.dev/blog/redirecting-root-domain-with-cloudflare/</link><pubDate>Wed, 28 Aug 2024 00:00:00 +0000</pubDate><guid>https://derekarmstrong.dev/blog/redirecting-root-domain-with-cloudflare/</guid><description>&lt;hr&gt;
&lt;p&gt;You know the old saying, &amp;ldquo;It’s always DNS&amp;rdquo;? Well, it&amp;rsquo;s true. And the more you dabble in the wonderful world of web management, the more you realize just how much your digital kingdom rests on those little DNS settings. Whether you’re managing a massive web empire or just tinkering with your personal site, knowing how to tame your network infrastructure is like having the keys to the castle. So let&amp;rsquo;s get into it and setup a redirect at the root level domain together!&lt;/p&gt;
&lt;h3 id="example-scenarios"&gt;Example Scenarios&lt;/h3&gt;
&lt;p&gt;Redirecting a root domain using Cloudflare is a common practice in various scenarios, especially when managing web traffic, branding, or SEO. Here are some scenarios where someone might need to do this:&lt;/p&gt;
&lt;h4 id="1-branding-and-consistency"&gt;1. Branding and Consistency&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Redirecting Non-www to www&lt;/strong&gt;: Because we all want to look sharp and consistent, right? You might want all traffic to go to
instead of
. This helps ensure that users always see the same version of your site, like having all your socks match—because mismatched URLs are just as bad as mismatched socks.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Redirecting www to Non-www&lt;/strong&gt;: Or maybe you’re a minimalist and prefer the sleek, no-frills
as your primary URL. In that case, you’ll be redirecting everything from
to
. Just like ditching that unnecessary &amp;ldquo;www&amp;rdquo; clutter.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="2-domain-consolidation"&gt;2. Domain Consolidation&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Merging Multiple Domains&lt;/strong&gt;: Got a handful of domains (e.g.,
,
)? It’s like trying to herd cats. Consolidate them by redirecting all traffic to a single domain (
), so everything points in the same direction. It’s domain feng shui.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Rebranding&lt;/strong&gt;: Changing your domain from
to
? Redirect the old root domain to the new one to keep all your loyal visitors (and your SEO rankings) in tow. Think of it like forwarding your mail after moving to a fancy new digital address.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="3-seo-and-duplicate-content"&gt;3. SEO and Duplicate Content&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Avoiding Duplicate Content&lt;/strong&gt;: Google frowns upon duplicate content like a librarian shushing a noisy visitor. To avoid penalties, you’ll want to redirect all traffic to a single canonical URL (e.g.,
redirects to
). Because let’s be honest, duplicate content is just unnecessary noise.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Maintaining SEO Rankings&lt;/strong&gt;: Migrating to a new domain? Redirect the old root domain to the new one, and watch as your hard-earned SEO rankings follow you to your shiny new home. It’s like changing the address on your business card but with way more techy jargon involved.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="4-traffic-management"&gt;4. Traffic Management&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Temporary Redirects During Maintenance&lt;/strong&gt;: Sometimes your website needs a little TLC. Set up a temporary redirect to a maintenance page (
) so your visitors know you haven’t vanished into the digital abyss.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Redirecting to a Regional or Language-Specific Site&lt;/strong&gt;: Got a global audience? Redirect users from the root domain to region-specific sites (
to
for U.S. visitors). It’s like rolling out the red carpet, tailored to each visitor.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="5-domain-migration"&gt;5. Domain Migration&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Moving to a New TLD&lt;/strong&gt;: Making the leap from &lt;code&gt;.com&lt;/code&gt; to &lt;code&gt;.dev&lt;/code&gt;? Redirect the old domain (
) to the new one (
), and keep everyone on the right track. Think of it as leaving breadcrumbs for your visitors to follow.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Transition from a Development or Staging Environment&lt;/strong&gt;: Your site is graduating from staging (
) to production! Redirect the root domain to ensure all traffic flows to your up-to-date masterpiece.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="6-preventing-domain-squatting"&gt;6. Preventing Domain Squatting&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Protecting a Brand&lt;/strong&gt;: Own multiple variations of your domain to protect your brand? Redirect those variations to the main site to prevent confusion and keep domain squatters at bay. Because nobody likes a digital trespasser.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="7-simple-url-forwarding"&gt;7. Simple URL Forwarding&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Redirecting to a Social Media Profile&lt;/strong&gt;: Not quite ready for a full website? Redirect your root domain to a social media profile (
to
). It’s like handing out your business card, but online.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Redirecting to a Third-Party Service&lt;/strong&gt;: If your domain is just a gateway to another service (e.g., a blog hosted on Medium or a store on Shopify), redirect it there (
to
). Because who said you need to build everything from scratch?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="8-dealing-with-expired-services"&gt;8. Dealing with Expired Services&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Redirecting After Expiring or Discontinuing a Service&lt;/strong&gt;: If a service or site is no more, its root domain can be redirected to another service or a page explaining the change. It’s like leaving a &amp;ldquo;We’ve Moved&amp;rdquo; sign up for your digital neighbors.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="step-by-step-guide-to-redirect-a-root-domain-using-cloudflare"&gt;Step-by-Step Guide to Redirect a Root Domain Using Cloudflare&lt;/h3&gt;
&lt;p&gt;Alright, enough scenarios. Let’s get down to business and set up that redirect!&lt;/p&gt;
&lt;h4 id="1-log-in-to-cloudflare"&gt;1. Log in to Cloudflare&lt;/h4&gt;
&lt;p&gt;First things first, log in to your
.&lt;/p&gt;
&lt;h4 id="2-select-your-domain"&gt;2. Select Your Domain&lt;/h4&gt;
&lt;p&gt;From your list of domains, click on the one you want to redirect.&lt;/p&gt;
&lt;h4 id="3-set-up-dns-records"&gt;3. Set Up DNS Records&lt;/h4&gt;
&lt;p&gt;To make sure traffic to
flows smoothly through Cloudflare, set up these DNS records:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Root Domain A Record (&lt;/strong&gt;
):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Type&lt;/strong&gt;: A&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Name&lt;/strong&gt;: &lt;code&gt;@&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;IPv4 Address&lt;/strong&gt;: &lt;code&gt;192.0.2.1&lt;/code&gt; (Just a placeholder, doesn&amp;rsquo;t actually matter)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;TTL&lt;/strong&gt;: Auto&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Proxy status&lt;/strong&gt;: Proxied (Orange Cloud)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;www&lt;/code&gt; Subdomain A Record (
):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Type&lt;/strong&gt;: A&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Name&lt;/strong&gt;: &lt;code&gt;www&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;IPv4 Address&lt;/strong&gt;: Same as above (&lt;code&gt;192.0.2.1&lt;/code&gt;)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;TTL&lt;/strong&gt;: Auto&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Proxy status&lt;/strong&gt;: Proxied (Orange Cloud)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Pro Tip&lt;/strong&gt;: Prefer a CNAME? No problem. Use this instead:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;CNAME Record for Root Domain&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Type&lt;/strong&gt;: CNAME&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Name&lt;/strong&gt;: &lt;code&gt;@&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Target&lt;/strong&gt;:
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;TTL&lt;/strong&gt;: Auto&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Proxy status&lt;/strong&gt;: Proxied (Orange Cloud)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="4-create-a-page-rule-for-the-redirect"&gt;4. Create a Page Rule for the Redirect&lt;/h4&gt;
&lt;p&gt;Now for the fun part: setting up the Page Rule to actually do the redirecting.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;In your domain’s dashboard, head over to &lt;strong&gt;Page Rules&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;strong&gt;Create Page Rule&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the &lt;strong&gt;&amp;ldquo;If the URL matches&amp;rdquo;&lt;/strong&gt; field, enter
(This little wildcard &lt;code&gt;*&lt;/code&gt; will capture everything after the root domain).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Under &lt;strong&gt;&amp;ldquo;Then the settings are&amp;rdquo;&lt;/strong&gt;, select &lt;strong&gt;Forwarding URL&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Choose your redirect type:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;301 - Permanent Redirect&lt;/strong&gt;: This is your &amp;ldquo;Forever&amp;rdquo; option.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;302 - Temporary Redirect&lt;/strong&gt;: Just temporary? Use this.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the &lt;strong&gt;&amp;ldquo;Enter destination URL&amp;rdquo;&lt;/strong&gt; field, type the URL you want to send folks to, like
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;$1&lt;/code&gt; is the bit that keeps all your existing links like &lt;code&gt;example.com/some/path&lt;/code&gt; working. In short it keeps your old paths intact.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;strong&gt;Save and Deploy&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id="5-test-the-redirect"&gt;5. Test the Redirect&lt;/h4&gt;
&lt;p&gt;Now’s the moment of truth. Go to
in your browser and make sure you land at
or wherever you’ve decided to send your traffic. If it works, give yourself a high-five—you’ve just mastered DNS redirection like a pro.&lt;/p&gt;
&lt;blockquote class="border-l-4 border-neutral-300 dark:border-neutral-600 pl-4 italic text-neutral-600 dark:text-neutral-400 my-6"&gt;
&lt;p&gt;To redirect both
and example.com to newdomain.com, you need to create a separate page rule for each address.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id="summary-example-configuration"&gt;Summary Example Configuration&lt;/h3&gt;
&lt;p&gt;Here’s a quick recap of what you’ve just done:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;DNS Settings&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A Record&lt;/strong&gt;: &lt;code&gt;@&lt;/code&gt; → &lt;code&gt;192.0.2.1&lt;/code&gt; (Proxied)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A Record&lt;/strong&gt;: &lt;code&gt;www&lt;/code&gt; → &lt;code&gt;192.0.2.1&lt;/code&gt; (Proxied)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Page Rule&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;URL Pattern&lt;/strong&gt;:
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Setting&lt;/strong&gt;: Forwarding URL →
(301 - Permanent Redirect)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Congrats! By following these steps, you’ve ensured that your root domain is successfully redirected using Cloudflare’s DNS and Page Rules features. Go forth and redirect with confidence—because when it comes to DNS, you’re now in the driver’s seat!&lt;/p&gt;
&lt;h2 id="key-takeaways"&gt;Key Takeaways&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;You can redirect a root domain with Cloudflare using Page Rules (or DNS with a CNAME at the root, since root-level CNAMEs aren&amp;rsquo;t always supported)&lt;/li&gt;
&lt;li&gt;Set up an A record for &lt;code&gt;@&lt;/code&gt; pointing to a placeholder IP, enable proxy (orange cloud), then create a Page Rule to forward the URL to your target domain&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;$1&lt;/code&gt; placeholder in the forwarding URL preserves the original path—so &lt;code&gt;/about&lt;/code&gt; becomes &lt;code&gt;example.com/about&lt;/code&gt; instead of dropping to the root&lt;/li&gt;
&lt;li&gt;You need separate rules for each domain. If you&amp;rsquo;re redirecting &lt;code&gt;example.com&lt;/code&gt; and &lt;code&gt;www.example.com&lt;/code&gt; to the same place, create two rules with each source domain&lt;/li&gt;
&lt;li&gt;Cloudflare&amp;rsquo;s pricing determines rule counts: Free tier gets 3 Page Rules, Pro gets 20, Business gets unlimited&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="next"&gt;Next&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
— another Cloudflare integration, this time for routing traffic through tunnels&lt;/li&gt;
&lt;li&gt;
— infrastructure that benefits from proper DNS and domain management&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>