I
I
invisii2019-10-10 10:55:05
Nginx
invisii, 2019-10-10 10:55:05

How to make a redirect with a question mark at the url in nginx and apache?

Good day. Actually for Apache there are 301st redirects of this kind:
Redirect 301 /?p=59 site.com/work-release-form
But because of the question mark, it refuses to work. It is also needed under nginx, and again
location /?=59 { rewrite ^(.*)$ /work-release-form/ redirect; }
Tried to escape a question mark - gives nothing. Please tell me the correct way.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2019-10-10
@invisii

Neither apache nor nginx considers query parameters (question mark etc.) to be part of location

location / {
  if ($arg_p = 59) {
    return 302 /work-release-form/;
  }
}

Perhaps the location will need to be changed depending on the rest of the config.
Also, 302 should be changed to 301, but only when you are 146% sure that everything is working correctly. Otherwise, you are tormented by cleaning redirects from browser caches.

I
invisii, 2019-10-10
@invisii

yes, under nginx it worked, thanks!
Tell me more under Apache how to make redirects like:
Redirect 301 /?p=59 site.com/work-release-form

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question