Currently I have something like this in my nginx.conf file:
location ~ /old/page/?$ {
return 301 /new-page;
}
The issue is that query strings are being stripped from the /old/page?ref=xx URL.
Is it possible to include query strings using the redirect method I'm using above?
Anything from the ?
and after is the query string and is not part of the normalised URI used in location
and rewrite
directives. See this document for details.
If you want to keep the query string, either add it to the return
:
location = /old/page/ {
return 301 /new/page$is_args$args;
}
Or with rewrite
, the query string is automatically appended unless a ?
is added:
rewrite ^/old/page/$ /new/page permanent;
See this document for location syntax, and this document for return/rewrite.