If you are on Hubspot CMS starter you probably have noticed that you can't use your root domain (non-www) as your website. I believe this is because of how Hubspot works internally with the CDN servers to provide a great overall service.

This is usually not a great experience if you are migrating your website because you may need to handle all the redirects from the old website to the new one to keep your current SEO ranking (I will talk about this in a different post).

Today we will focus on how to redirect your root domain, or HTTP(S).domain.com to HTTP(S).www.domain.com.

These are the main steps:

Step guide

0. Register your account on Cloudflare.
Step1: Click on add new site. Step 2: write your domain and click add site.
  1. Click on add a new site.
  2. Enter your domain.
  3. Go to DNS, check that the list imported from your current provider matches all your current options (mine was quite large and was missing a few subdomains and the TXT entries, so double-check and add them!).
  4. Find your CNAMEs related to Hubspot, make sure to click on edit each of them, and disable proxy. Mine were:: www hs1-353382._domainkey and hs2-353382._domainkey. This is an important step, while your website will work. Hubspot won't be able to validate that it is redirecting properly and you won't be able to publish any new pages.
  5. Now it's time to update your current provider with the provided DNS servers that Cloudfire shows you on the page. This will depend on your current provider or where you bought your domain.
  6. Back to Cloudflare. Go to rules. On the free tier, we have 3, which is all we need 😊.
  7. Now we add the rules as Forwarding URL and 301 - Permanent redirect. Add the rules as follows:

    http://*.your-domain.com/*https://$1.your-domain.com/$2

    https://your-domain.com/*https://your-domain.com/$1

    https://your-domain.com/*https://your-domain.com/$1

You should end up with something like this:

cloudfire-https-and-www-redirect

With this setup, you have the basic setup to have your root domain redirected to https.www, but we can activate a few options on Cloudflare to increase the performance and squeeze the cache a bit.

Extra!

  1. Go to the Network tab.
  2. Double-check HTTP/2 and HTTP/3 are active.
  3. Activate 0-RTT
  4. Go to the Speed tab → Optimization.
  5. Activate Brotli, and Early Hints (when I did it, it was an opt-in beta).
  6. Keep scrolling down until Rocket Loader and activate that one too!

Now you can go back to Speed tab → Overview and do a test to see how fast your website is now!

Update:

I am not 100% sure if these extra steps will improve your performance much, because we disabled previously the proxying for the CNAMEs of Hubspot, and I believe this won't be in effect any longer, but it won't hurt activating it just in case :).

Enjoy!