How to setup subdomain redirects
I have a domain name (example.com) and I want to route twitter.example.com and example.com/twitter to my twitter account. I have written 2 separate rules in a
_redirects
file but they are not working. I am not sure how to troubleshoot it. can someone help me please?
here are the 2 rules:
I had redirect rules but I disabled them so I could only use this feature instead and have many more URLs to be available to redirect.12 Replies
_redirects doesn't support domain level redirects, i.e https://twitter.example.dev wouldn't work, the source can only be a path. It needs to be a fully qualified url including the scheme as well, i.e
The build log is helpful at debugging redirects, ex it'll tell you
10:54:05.645 - #2 /twitter twiiter.com/example_com
10:54:05.645 URLs should either be relative (e.g. begin with a forward-slash), or use HTTPS (e.g. begin with "https://").
ok thanks. but I dont think
was working either
What do build logs say?
_redirects and _headers only run on static assets as well, if you're using some framework like next-on-pages that has a function handling every request you'd have to use that framework's specific redirect stuff
I dont understand the explanation. I dont know what next-on-pages is. My website is just a very simple 1 page thing.
build log:
If you're using just static assets (no functions or javascript framework), then it doesn't apply. You've still got a ton of errors there, and you haven't fixed /twitter to include https://
oh yeah, I just added the https:// to twitter links. how do I fix the other errors? also should the
mailto:email
have https://
before it?I don't think you'll be able to get mailto working from _redirects, and the other errors can't be fixed, _redirects just doesn't support domain level redirects (i.e all it supports is relative paths like
/email
for source)hmm ok, thanks for your help. what are my options if I want domain level redirects? will I have to use page rules?
Page rules will eventually be going away, Bulk Redirects or Dynamic/Single Redirects are your options. Bulk Redirects are account-wide, but you get more of them, Single Redirects are zone/website specific, supporting more complex operations and a bit harder to make it preserve path (if you wanted to do that)
How do I access/use bulk redirects?
https://developers.cloudflare.com/rules/url-forwarding/bulk-redirects/create-dashboard/
Account level -> Bulk Redirects, create and walk through the steps
Create Bulk Redirects in the dashboard · Cloudflare Rules docs
To create Bulk Redirects in the Cloudflare dashboard you must:
thanks for your help :)