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.

Hatclock
  • 13
  • 5
  • please share your Nginx config. I don't believe it is coming from the webserver – djdomi Aug 28 '19 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 '19 at 12:16

1 Answers1

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

Richard Smith
  • 12,834
  • 2
  • 21
  • 29