1

I have a site which has an issue causing an annoying URL issue. On the page numbers found on a page, if you follow one it will visit ?page=2, this is fine.

If you then follow any subsequent links, rather than replacing the ?page=2, it will append a new one. For example: ?page=2&page=3. For various reasons, I need this to be ?page=3 and to remove the extroneous parameter from the beginning.

Sadly fixing this in code is not possible at this time and I wonder if anyone has ever done something similar through an NGINX rewrite.

2
  • please share your Nginx config. I don't believe it is coming from the webserver
    – djdomi
    Aug 28, 2019 at 12:12
  • This issue is not coming from the webserver, I am wondering if I can use the rewrite function on NGINX to patch it up (even badly).
    – Hatclock
    Aug 28, 2019 at 12:16

1 Answer 1

0

You cannot fix this using the rewrite as it only operates on the part of the URI before the query string.

The query string is contained in the $request_uri and $args variables, which can be manipulated using regular expressions with if and/or map directives.

To process your specific case, you could use:

if ($request_uri ~ ^(.*)[?]page=2&page=(.*)$) { return 301 $1?page=$2; }

For an example using map, see this answer: Nginx - Redirect based on query string parameters

1
  • That's exactly what I was hoping for, thank you!
    – Hatclock
    Aug 28, 2019 at 13:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .