How to redirect with query string in Nginx

6,038

But the q parameter is empty on redirection.

I don't see that problem. When I test the configuration as written, it creates a redirection loop because the original keywords='value' is appended to the rewritten URI.

You can prevent rewrite from including any original parameters by appending a ? to the rewritten URI.

For example:

rewrite ^ /search?q=$arg_keywords? permanent;

See this document for details.

Share:
6,038
Ordidaad
Author by

Ordidaad

Updated on September 18, 2022

Comments

  • Ordidaad
    Ordidaad almost 2 years

    I would like to redirect:

    something.com/search?keywords='value'
    

    to

    something.com/search?q='value'
    

    Here is my Nginx config:

    location ~ /search {
           if ($args ~* "keywords=(.*)") {
                rewrite ^.*$ /search?q=$arg_keywords permanent;
            }
        }
    

    But the q parameter is empty on redirection.

    What is wrong?