Lille Hummer
Lille Hummer

Reputation: 629

NGINX redirect that matches query string

We've migrated from an old system to a new website. I have a lot of old URL's that look like this:

/index.php?id=1&groep=26

/site/index.php?id=1&groep=10

New URL's look like:

/medical-information/test-results

There is no pattern to rewrite these URL's and each has to be done manually.

How can I redirect these with NGINX? It seems it doesn't match the query string after the index.php part.

Thanks a bunch!

Upvotes: 2

Views: 5554

Answers (1)

Aleksandar
Aleksandar

Reputation: 2642

I would suggest to use a map with $arg_groep and a rewrite.
http://nginx.org/en/docs/http/ngx_http_map_module.html
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite

You can find a example here
https://serverfault.com/questions/609042/nginx-map-directive-for-multiple-variables.

my suggestion.

map $arg_groep $dest {
  26 /medical-information/test-results;
  10 /some/other/URL;
}

rewrite ^/index.php?id=1&groep=26 $dest permanent;

You will finde some more examples via this search query.
https://www.startpage.com/do/dsearch?query=nginx+map+args

Upvotes: 3

Related Questions