J
J
JRazor2019-04-03 18:06:26
Nginx
JRazor, 2019-04-03 18:06:26

Nginx: how to set up a redirect by subdomain and request_uri?

Good evening!

Can you please tell me how to configure the following condition in nginx:

if ($host = sobdomain.domain.com) {
  if ($request_uri = ^\/(login|signup)$) {
    return 301 https://other.site
  }
}


That is, provided that a certain subdomain and a certain URL are used, redirect to another site.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2019-04-03
@dodo512

map $host$request_uri $_url {
    ~^([^?]*)  $1;
}

server {
    if ($_url ~ "^subdomain\.domain\.com/(login|signup)$") {
        return 301 https://other.site/;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question