Cannot strip QS in rewrite

Maxim Dounin mdounin at mdounin.ru
Thu Jun 20 15:21:41 UTC 2019


Hello!

On Thu, Jun 20, 2019 at 05:05:57PM +0200, aquilinux wrote:

> Hi guys, i've always used ? to strip QS in rewrites but i cannot get past
> this odd issue i'm having:
> 
> URL SOURCE:
> 
> > https://www.example.co.uk/ambassadors?test=1
> 
> 
> REWRITE:
> 
> > rewrite (?i)^/ambassadors$
> > https://www.example.com/uk-en/experience/ambassadors/? permanent;
> 
> 
> OR EVEN:
> 
> > location ~* ^/ambassadors$ {
> >   rewrite (.*) https://www.example.com/uk-en/experience/ambassadors/?
> > permanent;
> > }
> 
> 
> RESULT WITH REWRITE:
> 
> > [~]> curl -kIL https://www.example.co.uk/ambassadors?test=1
> > HTTP/2 301
> > date: Thu, 20 Jun 2019 14:44:21 GMT
> > content-type: text/html
> > location: https://www.example.com/uk-en/experience/ambassadors/?test=1
> > x-who: SVAORMG2V01

An nginx response is expected to contain "server: 
nginx/<version>", for example:

$ curl -kI https://127.0.0.1:8443/ambassadors?test=1
HTTP/2 301 
server: nginx/1.17.1
date: Thu, 20 Jun 2019 15:11:51 GMT
content-type: text/html
content-length: 169
location: https://www.example.com/uk-en/experience/ambassadors/

Are you sure the response you've provided is from nginx?

(Also, as you can see from the above example response, the rewrite 
is working fine.)

You may also want to drop "-L" from your curl options to make sure 
you are looking at a particular response, and not a chain of 
redirects.

If the above doesn't help, you may consider using "rewrite_log on;" 
to find out how your rewrites are processed (see 
http://nginx.org/r/rewrite_log for details).

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list