Naked Domain Redirect CloudFlare

less than 1 minute read

Description:

I needed a way for people to get to my site without having to type “www” in the address bar. I first used a service called “wwwizer” but then found that you can do this WITHIN CloudFlare by setting up “Page Rules”. NOTE: You only get 3 with a free domain, but you only need 1 for this.

To Resolve:

  1. Sign into CloudFlare and then go to Page Rules. Create one that:

    example.com/*  
    # forwarding URL - 301 Permanent Redirect  
    http://www.example.com/$1
    
    • From the link: The solution is to use variables. Each wildcard corresponds to a variable when can be referenced in the forwarding address. The variables are represented by a $ followed by a number. To refer to the first wildcard you’d use $1, to refer to the second wildcard you’d use $2, and so on.

    • In this case, if someone went to: example.com/some-particular-page.html
    • They’d be redirected to: http://www.example.com/some-particular-page.html
  2. That’s it; it just works!

References:

https://support.cloudflare.com/hc/en-us/articles/200172286-How-do-I-perform-URL-forwarding-or-redirects-with-CloudFlare-