Redirect like "/paintings page=:page /paintings-page-:page 200" not working as intended

Hi,

I noticed some of my redirect rules are not working. I think I would have verified that they worked when I added them, and that they have broken since, but I’m not sure.

One example rule is

/paintings page=:page /paintings-page-:page 200

which is meant to make e.g. https://18thcenturyblog.johannaost.com/paintings?page=2 show https://18thcenturyblog.johannaost.com/paintings-page-2 but as you can see by visiting those URLs, the first one is not so rewritten – it just renders https://18thcenturyblog.johannaost.com/paintings and ignores the param.

This site is a static mirror of an old blog, and this was intended as a workaround so the pagination could keep working with the old URLs.

@henrik Did the forum software replace the question mark with a space in your example?

The rules look correct (based on the documentation) so I think potentially the issue is that your redirects are not applying at all: do you have any working redirect rules? I’d probe whether or not there’s an error with your _redirects file formatting or file placement.

:warning: Make sure we can access the file
If you’re running a build command or site generator, the _redirects file should end up in the folder you’re deploying.

As an aside, you might find it easier to use the netlify.toml configuration file because it’s clearer what exactly the rule is configured to do, and you could use the splat functionality because your website uses the page pagination in quite a few places.

[[redirects]]
  from = "/*"
  query = {page = ":page"}
  to = "/:splat-page-:page"
  status = 200

This example would rewrite:

/paintings?page=2 -> /paintings-page-2
/links?page=4 -> /links-page-4

Also, minor note about language: a 200 is a rewrite so the URL will not change – it might be easier when debugging to use a 302[1] so you can see exactly which URL you’re being sent to and then switch to a 200 once you’re happy (if you do desire rewrites instead of redirects) :slight_smile:

[1] don’t use a 301 to debug because your browser will cache it which can cause a headache: a 301 should only be used once you’re happy and willing to commit to a redirect for the rest of time.

1 Like