I’ve got a website which used to be on WordPress which I’ve redesigned to be a simple landing page. I’ve got the domain in Cloudflare and I’ve set up a Page Rule to 301 redirect www as follows:
This rule is working, and directs any visits to the root domain to the www version.
It also redirects any visits to /foo/bar to www.mydomain.com, which is exactly what I want to happen. Everything to the one base URL.
However, I would also like to redirect any visits to www.mydomain.com/foo/bar, so if anyone visits any of the old WordPress paths AND uses the www subdomain, they’ll also just get redirected to www.mydomain.com
I’ve fiddled around with additional page rules and redirects but I can’t seem to find the right method to add this additional “wildcard” behavior without disrupting what I’ve already got working. I’ve reviewed the CF documentation for all these areas but I can’t seem to figure out how to apply those examples to my situation.
Any suggestions would be greatly appreciated. Thanks!
Domains like e.g. example.com, example.net and example.org are standardized as example domains, such as for use in e.g. documentation, and, like in your case if you are not actually sharing a real domain name.
You can use Redirect Rules (rather than Page Rules), which would offer much more granularity.
which would redirect both https://example.net and https://www.example.net, but only with the URI PATH /foo/bar to https://example.com
The different variables and such you can use, would be available here:
I’m not sure that I’m catching the part about “wildcard”, as it also sounds like you want to be very selective with what you are redirecting?
So I guess the best way would be, if you would elaborate what exact stuff that you do already have working, that you don’t actually want to disrupt, including what exact rules you tried, that was disrupting what you had already?
If you are looking to redirect /foo/bar alone, and only on the www. hostname, you can do that with a Redirect Rules, like this:
Thank you very much for the notes so far. I think I may have misused “/foo/bar” in my original post, in that I think it may have communicated I want to redirect one particular path, or perhaps even a fixed set of particular paths.
Rather, I am hoping to redirect all URLs from the old iteration of the website to just land on the new “home” page.
What I’m hoping to have happen is that visits to any of the following URLs will get redirected to https://www.example.com/
https://example.com/
https://example.com/blog/
https://www.example.com/blog/
https://example.com/blog/article/
https://www.example.com/blog/article/
Any other substitute in place of “blog” or “article” in the examples above. This is what I meant about a “wildcard” kind of effect, I just didn’t know how to express it. Essentially, I’m hoping to come up with something where everything after https://www.example.com/ in the URL gets ignored or in a way, stripped.
As of right now, from the list above the following items are working as desired: 1, 2, and 4.
The following items are not working: 3, 5, and 6.
At this time, what I have in place are a DNS A record for @ and a CNAME record for WWW.
And I have one page rule in place as follows: https://example.com/* - Forwarding URL (Status Code: 301 - Permanent Redirect, Url: https://www.example.com/ )
It seems like items 3, 5, and 6 may all be examples of the same problem, I just can’t figure out how to implement a rule to address it without getting into redirect loop trouble.
I hope this clarifies the problem. Thank you again for the notes so far, and I’m going to review those in more detail later to learn all that I can. It seems like your last example of the dynamic AND rule may be very close to what I will need to implement, but because of the confusion I caused with my use of foo/bar I’m not sure…
But do you also require that wildcard part (e.g. /blog/article/ here) from the old site, to be carried on to the new site?
If someone is trying to enter https://www.example.NET/blog/article/ (the old domain), when they are being redirected to example.COM (the new domain), do you want them to get to:
https://www.example.COM/
https://www.example.COM/blog/article/
Your current set up signals that you just want the “naked” URI path (#1)?
However, if you require them to still reach the exact blog post that the old link used to refer to, I would say that you would need the same URI path to be passed on to the new domain (#2)?
This part, with “home”, sounds like #1?
If #1 is correct, I would move on with the first example from above:
→ Remove / uncheck “Preserve query string”.
→ Kill your old Page Rule for the redirect, as this Redirect Rule will take care of redirecting both (e.g. example.net and www.example.net) to https://example.com for you.