Cloudflare DNS: How to 301 Redirect all traffic from Sub Domain to Main Domain with URL path?
18,859
The error you are receiving is because CNAME's only support domain names and not URL paths. You can setup a redirect using your hosting account or Cloudflare Page Rules.
14 Step Cloudflare Process in redirecting traffic from subdomain to main domain using Page Rules:
- Login to Cloudflare
- Use the drop-down menu in the upper left of your screen and click your domain that you want the redirect to take place on.
- Click the DNS icon at the top of the screen.
- Select
CNAME
using the drop-down options - Add the sub domain in
NAME
- Add your domain name in
Domain name
- Leave TTL as automatic and Cloudclare enabled, click
Add Record
button. - Click Page Rules icon
- Click Create Page Rule button
- Add
alexa.example.com/*
in the URL match field - Click + Add a Setting, find
Forwarding URL
and click it - Select the status code
301 - Permanent Redirect
- Add the Enter destination URL as
http://example.com/alexaSkillDemo
- Click Save and Deploy button.
Related videos on Youtube
Author by
user4358892340
Updated on September 18, 2022Comments
-
user4358892340 over 1 year
I am using cloudflare to manage my domain, and I wanted to add a subdomain. I tried to do this:
But it gives me an error. How would I add a subdomain like blog.example.com that sends to example.com/blog ?
-
Simon Hayter about 7 yearsDo you mind if the URL redirects or do you want it masked? you won't be able to use Cloudflares free SSL if you want it to MASK. Mask =
blog.example.com
appears in the address bar, redirect =blog.example.com
changes toexample.com/blog
-
Stephen Ostermiller almost 7 yearsYet another question from somebody who is confused between DNS CNAME and HTTP redirects. :( I feel like we get two of these a week.
-
-
user4358892340 about 7 yearsNot sure what you mean with option 2. I'm hosting on github pages, so not really sure what to do
-
Simon Hayter about 7 yearsI've updated the answer... just follow those 14 steps and your good to go.
-
user4358892340 about 7 yearsIs there any way to do it without using a page rule, as I only have one left, and I was hoping to add other subdomains
-
Simon Hayter about 7 yearsOkay so you want to use a GitHub Repository with your sub domain?
-
user4358892340 about 7 years
-
phfeiler almost 4 yearsIf things still don't work, try setting up an HTML redirect like this github.com/deepdrive/smooth-redirect - I think doing so allowed the page rule to take effect as the underlying CNAME link was now returning, meaning the HTML redirect is not used at all, but serves as a kind of backup I guess.