0

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.

  1. Can't if in an if block -> Nginx Remove Trailing Question Mark From URL
  2. 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

  • Does this answer your question? [In Nginx, how can I rewrite all http requests to https while maintaining sub-domain?](https://serverfault.com/questions/67316/in-nginx-how-can-i-rewrite-all-http-requests-to-https-while-maintaining-sub-dom) – djdomi Jun 13 '23 at 04:35
  • Unfortunately not, I updated the question to further clarify what I'm trying to achieve. – jordantrizz Jun 14 '23 at 15:30
  • please verify with [ask] there is a ton of information missing – djdomi Jun 14 '23 at 17:34
  • @djdomi a "ton" is exaggerating, I've improved the question. If you look back at all my edits, they had nothing to do with HTTP to HTTPS. – jordantrizz Jun 16 '23 at 19:28
  • [How-to Ask - the extended](https://meta.serverfault.com/questions/6074/do-you-have-a-checklist-that-can-help-me-ask-a-better-question). Nope, you are just fixed the formatting. But rather included the required section as I told or look similar like: [how do I get better answers](https://meta.serverfault.com/questions/237/how-do-i-get-better-answers) - What I wanted to tell you is, we are just the last edge of your search and not a solution booth that magically can read glass balls without any knowledge about the situation. ;) or with a similar its like Housten weve got a problem" -thats it ;) – djdomi Jun 17 '23 at 08:39
  • @djdomi I took another wack at it, I just don't know what else to put in the question. This is my first time posting a question so I thank you for the feedback. I've been on the reverse side, and perhaps I have a blind spot in this case and can't see what I'm missing. – jordantrizz Jun 21 '23 at 12:05

0 Answers0