I'm trying to redirect URI's ending in a single question mark to the same URI with the single question mark removed. Running nginx/1.21.6
Here's an example.
Original Request:
https://domian.com/product-category/product/?
Redirect to:
https://domian.com/product-category/product/
I've tried the following questions, which don't work.
- Can't if in an if block -> Nginx Remove Trailing Question Mark From URL
- Map doesn't seem to work -> nginx: [emerg] "if" directive is not allowed here
Looking at the nginx access log requests with a single question mark and nothing else on the end of the URI aren't logged with a question mark. Perhaps this is by design with nginx? Does it mean nginx doesn't record these requests, as they essentially contain no data?
Why do I need this? Google sees pages with a single question mark as valid pages because they return a 200 status code. If Google sees a page with a question mark and the same page without a question mark, the page with a question mark gets marked as a duplicate. Resulting in warnings within the Google Search console.
I would like to have these pages with a single question mark 301 redirected so these warnings are removed from Google Search Console