Bulk Redirects - Strict matching?

I’m trying to do strict redirects where if the Source URL has parameters, it will not be redirected.

Lets say:

Source: http://google.com/test.html
Destination: http://google.com/new

When http://google.com/test.html?product_list_limit=24 URL is visited, then the redirect should not work.

Currently, the parameters are ignored and just redirected to the http://google.com/new page.

I have tried all the options in the list:

image

But they make the situation worse and just add the URL parameters to http://google.com/new?product_list_limit=24 URL.

Please let me know if this is planned or maybe I’m missing something?

Hello @user17758,

Bulk Redirects use a URL matching algorithm that prioritizes the most specific redirect, but you actually can make them less strict with those parameters.

Tip

Do not use a scheme (http or https) on source URLs to match both at the same time. For example:

Source URL example.com/test

Target URL https://example.com/new

Status 301

…will match http://example.com/test and https://example.com/test

Parameters

Preserve query string - No

Include subdomains - No

Subpath matching - No

Preserve path suffix - No

Results

example.com/test/foo doesn’t redirect because of a 522 error (timeout) and the reason is you aren’t matching subpaths, so if present on incoming requests, the redirect fails.

example.com/test?product_list_limit=24 doesn’t redirect because of a 522 error (timeout) and the reason is you aren’t preserving query strings, so if present on incoming requests, the redirect fails.

www.example.com/test?product_list_limit=24 doesn’t redirect because of a 522 error (timeout) unless you actually have a working www subdomain that responds from an origin server, and the reason is you aren’t including subdomains, so if present on incoming requests, the redirect fails.

example.com/test does redirect to https://example.com/new because is the most specific match and no other parameters are being considered.

Important

You absolutely need a proxied (orange-clouded) A record for Bulk Redirects to work. In this example, the root domain (@) example.com must be present and proxied on your DNS configuration. The same applies for any subdomain you want to use with Bulk Redirects.

Otherwise, Cloudflare can’t evaluate your redirect rules and do the actual redirect from incoming requests. If you don’t have an origin server, point your A records to 192.0.2.1

Finally

Cloudflare documentation describes your situation as expected when explaining the redirect result if Preserve query string is disabled, but I couldn’t get that result.

Instead of redirecting example.com/test/?name=value to example.com/new/ per the documentation, I get a 522 error (timeout) with the settings I described for this reply. Those results are consistent in my opinion, while the documentation still lacks some clarifications or has some things partially wrong.

My recent discovery was that if you don’t omit the scheme (http or https), then the parameter Preserve query string behaves as described in the documentation, so I tested this example:

Source URL https://example.com/test

Target URL https://example.com/new

Status 301

Preserve query string - No

Include subdomains - No

Subpath matching - No

Preserve path suffix - No

…and the result was the same as yours.

https://example.com/test?product_list_limit=24 redirected to https://example.com/new

https://example.com/test/?product_list_limit=24 (with trailing slash after /test) doesn’t redirect because of a 522 error (timeout) and the reason is the trailing slash is not present in the source URL and I’m not matching subpaths.

So the scheme and/or a trailing slash on your source URLs can affect the results.

To accomplish your strict matching, just remove the scheme from the source URL and test with no parameters.

:upside_down_face:

1 Like

Thanks for replying.

I did not get any 522 errors - I think this is something related to your environment.

I cant modify the Source URL as it’s auto generated URL.

I’m working on a website that has autogenerated menus. Some of the menu items we want to redirect.

Currently we’re using NGINX redirects - which work, but they are slow.

I’ll play around a bit more with these, but it looks like what I’m asking for is not possible.

You might try a Bulk Redirect Worker. It doesn’t say anything about query strings, so I don’t know if they’re dropped, or part of the match and forward.

1 Like

Ah this might be too advanced. I wanted an easy win, but looks like I might have to do something else.

Thanks though!