Redirect www. URLs to non-www within Cloudflare

submited by
Style Pass
2024-11-17 04:00:05

Q: How do you redirect a www. URL to the non-www URL within Cloudflare? A: With a custom Redirect Rule! Cloudflare now supports using Redirect Rules to map a www. request to your root domain; This article walks you through setting one up.

I’ve occasionally run into the annoying problem of trying to map www. requests to the non-www version (aka the “root” or “apex”). Given I use Cloudflare to manage most of my domains, and given everything else they offer, I figured they’d have a way to re-map these routes.

Cloudflare’s Redirect Rules let you re-map requests to your website and forward them to another URL, including using wildcards (*) and wildcard passthroughs (${1}, ${2} etc.). These are what we’ll use to re-map a request from www.yoursite.com to yoursite.com.

You can specify a 30x status code for your redirect, which makes these quite versatile. You’ll almost certainly want to use a 301 redirect — as of mid-2016, they don’t affect SEO.

Leave a Comment