You might need to move your website every once in a while. This could be due to a redesign, rebranding, marketing landing page A/B testing, domain change, and traffic redirection to updated content.
In this article, we will cover the steps necessary to Create a Wildcard Redirect in Cloudflare. Creating a Wildcard Redirect will not require much knowledge. What you need to understand is to implement the rules correctly in your Cloudflare Account.
What is Wildcard Redirect?
Wildcard redirect is very helpful when you want to change the names of URLs in a directory or send users from any URL in a directory to another place.
With the help of wildcard redirect, you can redirect users from i.e "example.com/link"
to "example.com/links"
.
You can also use it to redirect users who are typing random urls on your website to your homepage or any other URL. i.e "abc.page.link"
to "abc.com/link"
. Let's begin!
How to Set up Wildcard Redirect Rules?
Step 1: Log in to your Cloudflare Account and choose your domain.
Step 2: Go to Rules.
Step 3: Click Create Page Rule under Page Rules tab.
Step 4: The Create Page Rule for your_domain
dialog opens.
Step 5: Under If the URL matches, enter the URL or URL pattern that should match the rule. i.e https://www.yourdomain.com/link/*
Enter the URL Directory from where you want to redirect users. Add an asterisk (*) character, at the end of the url, this is the wildcard symbol.
Step 6: Under Then the settings are, click Add a Setting.
Step 7: Select an option from the dropdown menu. For this tutorial we select Forwording URL.
You can include more than one setting per rule.
Step 8: Next click Select status code, then select an option from the menu according to you need.
Step 9: Go to Enter destination URL directory, where you want the users to get redirected. i.e https://yourdomain.page.link/$1
Add an $1 symbol at the end of the url.
.Step 10: From the Order dropdown, specify the desired order: First, Last, or Custom, i.e select First
Step 11: Choose a Save option:
Page Rule will now redirect every url from "https://example.com/link" directory to "https://example.page.link" directory. The $1 will be replaced with the url you entered after the "https://example.page.link" directory. So the url will be same and only the directory will change.
- Save as Draft to save the rule and leave it disabled. Note that disabled rules count towards the number of rules allowed for your domain.
- Save and Deploy to save the rule and enable it immediately.
Note
Cloudflare Page Rules do not support non-ASCII characters (for example, punycode/unicode domain). As a workaround, you can URL-encode the string using the Punycode converter.
How to Edit existing page rules?
Editing the wildcard redirect page rule in Cloudflare is not a rocket science.
Step 1: Log in to your Cloudflare Account and select your Domain.
Step 2: Select the domain where you want to edit your page rule.Click Rules.
Step 3: In the Page Rules tab, locate the rule to edit.
Step 4: Proceed to make the necessary changes, as follows:
- To enable or disable a rule, click the On/Off toggle.
- To modify the URL pattern, settings, or order, click the Edit button (wrench icon). In the dialog, enter the information you want to change.
How to Delete a Cloudflare Page Rule?
Step 1: Log in to your Cloudflare Account and select your Domain. Select the domain where you want to edit your page rule.
Step 2: Click Rules.
Step 3: In the Page Rules tab, locate the rule to edit.
Step 4: Click the Delete button (wrench icon) and confirm the deletion when prompted.
Final Words
Leave a comment below if you have any questions about the Cloudflare Wildcard Redirect, tutorial.
If you think this article was helpful, please share it with your friends and other people. I'm grateful.
Make sure to bookmark our website by pressing CTRL+D
, as I will be sharing more amazing posts and codes similar to this one in future entries.