G
G
gh0st_d0g2020-06-04 23:44:47
Nginx
gh0st_d0g, 2020-06-04 23:44:47

How to write an nginx redirect?

It is necessary for nginx to form the correct redirect from the index.php pages and possible get parameters to the page / and get parameters. So far there is the following:

map $request_uri $index {
  default "0";
  "~/bitrix/admin/" "0";
  "~/auth/" "0";
  "~^(.*)index\.(?:php|html)" "$1";
}

  if ($index != 0) {

    return 301 $index;
  }

Produces a redirect to the page with / considering exceptions and removing get parameters

I.e. for example from the page localhost/index.php?filter=1 to localhost/?filter=1.

And you also need an additional redirect from a page like localhost/?oid=15 where the number can change to a page without this parameter, while preserving possibly other parameters except oid.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-06-04
@dodo512

map $request_uri $index {
  default "0";
  "~/bitrix/admin/" "0";
  "~/auth/" "0";
  "~^(.*)index\.(?:php|html)(\?.+)?" "$1$2";
  "~^/\?old=\d+&(.+)"  "/?$1";
  "~^/\?old=\d+"       "/";
}

if ($index != 0) {
    return 301 $index;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question