Score:0

Nginx Redirecting Single Question Mark Request to Originaly URI

ua flag

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

djdomi avatar
za flag
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)
jordantrizz avatar
ua flag
Unfortunately not, I updated the question to further clarify what I'm trying to achieve.
djdomi avatar
za flag
please verify with [ask] there is a ton of information missing
jordantrizz avatar
ua flag
@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.
djdomi avatar
za flag
[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 ;)
jordantrizz avatar
ua flag
@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.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.