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:
- Click on add a new site.
- Enter your domain.
- 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!).
- Find your CNAMEs related to Hubspot, make sure to click on edit each of them, and disable proxy. Mine were::
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.
- 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.
- Back to Cloudflare. Go to rules. On the free tier, we have 3, which is all we need 😊.
- Now we add the rules as Forwarding URL and 301 - Permanent redirect. Add the rules as follows:
You should end up with something like this:
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.
- Go to the Network tab.
- Double-check HTTP/2 and HTTP/3 are active.
- Activate 0-RTT
- Go to the Speed tab → Optimization.
- Activate Brotli, and Early Hints (when I did it, it was an opt-in beta).
- 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!
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 :).