setting up a 301 redirect at CloudFlare
So you have a super popular "how to poop standing up" article đŠ, butt you just got a new domain hooked up on CloudFlare and are worried that all those people who bookmarked the old URL might not be able to find thew new one...
How to setup a CloudFlare 301 redirect using âpage rulesâ:
The process of setting up redirects using Cloudflareâs DNS is pretty simple. You add your domain, point the CloudFlare DNS records (A record & CNAME record) to Cloudflareâs server, and then setup a URL forwarding rule. Thatâs pretty much it.
The first two steps of this walkthrough have nothing to do with the actual CloudFlare 301 setup. They are the things you need to do before any of this works. So, if youâve already added your domain to your CF account and pointed your domain registrarâs nameservers to it â you can skip them and start at Step 3.
1. Add Domain to CloudFlare
At the dashboard (dash.cloudflare.com) of your CloudFlare account click the âAdd a siteâ button, and enter your domain on the next screen.
Once you do that, youâll be presented with pricing options. Just choose the free one (bottom of screen) and move on.
Cloudflare will scan for existing DNS records and bring them over.
Keep them or delete them â the choice is yours (and depends on what youâre trying to do).
Click continue, and youâll get your accountâs nameservers.
Youâll need to update your current domainâs nameservers, which you can find at the domain registrar â aka the place where you login to see your domain, and probably where you purchased it.
2. Update NameServers
I canât make a tutorial for updating nameservers at every web hosting company, because thereâs like a trillion of them.
But youâll just need to go to your account > select your domain > choose âedit nameserversâ or something similar > paste in the nameservers that Cloudflare gave you in the last step.
Now, it will take anywhere from 10 minutes to 48 hours for those changes to take effect. This is called propagation.
But you donât have to wait for that to continue. You will have to wait for it for all the things you do next to work, however.
3. Update CloudFlare DNS
This is where the actual process starts.
Go to your domain settings in CloudFlare and choose âDNSâ.
If redirecting the whole domain I usually start with deleting the current DNS records that CloudFlare ported over. Donât do that if you have records in there you need.
Yes, captain obvious I know but⌠Common sense isnât always so common in these extremely tense IT settingsâŚ
Next, weâre going to add in the CloudFlare DNS records you need for your URL Forwarding to work.
Click âAdd recordâ and add the following information, and click the âSaveâ button:
- Type: A
- Name: @
- IPv4 Address: 192.0.2.1
Now, click the âAdd recordâ button again, add the following information, and click the âSaveâ button:
- Type: CNAME
- Name: www
- Target: @
4. Setup Page Rules for URL Forwarding
Navigate to the âRulesâ area on the sidebar, then click âPage Rulesâ and click the âCreate Page Rule` button.
Now itâs time to set your 301s!
Iâm going to setup a 301 redirect to forward all traffic coming to âdomain Aâ to âdomain Bâ, but you can easily just change the URL & destination to fit your needs.
Follow these steps:
- Enter the URL pattern you want 301ing
- Click the dropdown and choose âURL Forwardingâ
- Select your âStatus Codeâ from the drop down (probably 301)
- Enter the destination
- Click âSave and Deploy Page Ruleâ
I entered the root domain, and put an asterisk ( * ) at the end, which means that if anyone goes to an inner url, like âdomain.com/whatever-asdfadfâ it will also get redirected.
You can setup inner URL specific 301s too.
Now, Iâm simply going to do the exact same thing again â but this time add the www. version.
Same steps from above:
- Enter the URL pattern you want 301ing
- Click the dropdown and choose âURL Forwardingâ
- Select your âStatus Codeâ from the drop down (probably 301)
- Enter the destination
- Click âSave and Deploy Page Ruleâ
Thatâs it! Youâre done!
You should be able to go to your forwarded domain, and be taken to the destination.
If it doesnât work, make sure:
- Youâve given enough time for your nameservers to propagate (see step #2)
- You clear the CloudFlare cache (if you transferred your domain from another Cloudflare account)
- You clear your browser cache, or try in âincognito modeâ (press
shift
+command
+n
on most browsers (MAC) to open an incognito window)
Free Gifts
Get the free How to setup a Cloudflare 301 Redirect checklist, and run it anytime you need to repeat this process.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home