S
S
shahneff2022-03-05 15:10:46
Nginx
shahneff, 2022-03-05 15:10:46

How to redirect nginx from part of url to url with a parameter?

How to redirect nginx from part of url to url with a parameter?

For example, there is an address

https://t.example.com/id/fO8niger and I need to redirect it to https://t.example.com?id=fO8niger

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2022-03-05
@shachneff

If you need a 301 redirect.

location ~ ^/id/(.+) {
    return 301 /?id=$1;
}

Or If you need an internal redirect
rewrite ^/id/(.+) /?id=$1 permanent;
rewrite ^/id/(.+) /?id=$1 last;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question