Redirect rules not working

Domain redirect exceptions (rules) are not working as expected.

We’re attempting to redirect all visitors to another domain EXCEPT visitors with certain IPs AND specific referring domains.

For example.

Let’s say I have domainA and I want to redirect all visitors to domainB. I also want visitors who click a link or button on domainB to be able to view domainA and not be redirected.

I also want to allow a visitor with a public IP of 123.456.789.012 (example IP) or etc. to be able to access domainA, also without being redirected.

Currently in Cloudflare > Websites> Rules > Redirect Rules
I have rules similar to the following:

If Hostname does not equal domainB
or
Referer does not equal domainB
or
IP Source Address does not equal 123.456.789.012

Then URL Redirect
Static domainB 301

The redirect is working. The issue we’re experiencing is that the rules exceptions are not. If the visitor is on domainB and click a link or button or the user that direct accesses domainA with the whitelisted IP address are not able to view domainA. Instead they are being redirected to domainB like all the other users.

Do you see anything with the above config that could be causing this issue or do you have any suggestions?

Thank you for your help.

Hi,

Are you talking about domains (exampleA.com vs exampleB.com) or subdomains? I ask because, if this is a redirect rule at domainA, the hostname field can only be domainA or one of its subdomains. Otherwise all requests will match your rule.

Try using only the two last statements, with the logical operator AND, instead of OR:

If Referrer does not contain DomainB AND
IP does not equal xx.xx.xx.xx

Then…

Hello,

Many thanks for your reply.

Correct, I’m referring to the TLD.

To simplify things too for the discussion, I’ve removed all but one rule. Here’s how it is now:
Hostname (we also tried “referrer” with no success), Does Not Contain, domainB
It then has a redirect of static to domainb 301

It may be easier to see the actual site and redirect in question. The screenshot below shows the actual domain at the top in red and the rule and redirect that is currently in place.
https://app.screencast.com/zfeOANrcjB77p

When you go to the URL in red you are correctly redirected to the correct page on the new domain (refer to the redirect URL in the screenshot). However, when you arrive on that page you’ll see a button when you arrive on that is labeled “…Account History”. When you click on the button you should be able to be brought back and have access the old site (red URL). Unfortunately we haven’t found a combination of configuration settings in the rule that accomplishes this.

Your thoughts are appreciated.

I can’t see anything in red.

Again, no request will ever arrive to DomainA without having hostname containing DomainA. Never. If you are setting this Redirect Rule at a Cloudlfare Zone == DomainA, then all requests arriving at Cloudflare for that zone will necessarily contain DomainA. This field should be used only to differentiate DomainA (naked domain) from sub.DomainA, not DomainA from DomainB.

I can’t see the URL you mention in red, so I can’t visit the page with the button Account History (which I guess is DomainB), I just visited your DomainA and the only button is for a newsletter subscription.

Instead of relying on referrer, which is something you do not control, as browsers may or not send the referrer header, due to privacy options, extensions etc., you should try to create a logic based on the path your button links to. If it’s not too specific, then use query string, and add one if necessary. This way you’ll have control of the redirection.

I think I must have sent the wrong screenshot URL earlier. Here is the correct one with domainA’s URL:
https://app.screencast.com/RNDfSJ7VDBC9a

So the goal is to allow a user that clicks the button on domainB to be able to view domainA. We could add a parameter to the button link URL. But it appears, as you pointed out, that the rules are not for the purpose intended. Is that correct? They seem like they should be straightfoward but aren’t functioning in a way that makes sense to me.

On your Cloudflare Zone for DomainA, try a redirect rule with the following logic:

If Query String does not equal = “buttonParam” AND
IP Address does not equal “xx.xx.xx.xx”
then
redirect to DomainB

This would redirect all requests to DomainA to DomainB, except those containing the “buttonParam” in their query string and those originating from you IP address.

However, you need to also add exclusions to assets that the page where the button URL will land may need to work:

If Query String does not equal = “buttonParam” AND
IP Address does not equal “xx.xx.xx.xx” AND
URI Path does not start with “/static/” [wherever needed files may be]
etc.