Nginx 301 redirect with query string

I currently have something like this in the nginx.conf file:

location ~ /old/page/?$ {
    return 301 /new-page;
}

Is the problem that query strings are removed from URL / old / page? ref = xx.

Is it possible to include query strings using the redirect method that I use above?

+4
source share
1 answer

Any of ?and after is a query string and is not part of the normalized URI used in locationand directives rewrite. See this document for more details .

If you want to save the query string, add it to return:

location = /old/page/ {
    return 301 /new/page$is_args$args;
}

rewrite , ?:

rewrite ^/old/page/$ /new/page permanent;

/.

+6

Source: https://habr.com/ru/post/1661973/


All Articles