D
D
D99100992017-04-25 00:01:03
Nginx
D9910099, 2017-04-25 00:01:03

How to compose a double redirect in nginx?

Hello,
I recently asked for help in redirecting a request.

Past appeal and decision
Appeal:
there is a domain and a site, there is a forum on it:
http://site.ru/forum/viewforum.php?f=4
it is moving to a new domain, and the forum has moved to the root
http://newsite.ru/viewforum.php?f=4
How to rewrite? Help me please.
Decision:
server {
        listen       80;
        server_name  site.ru;
    location ~ ^/forum/(.*)$ {
    return 301 http://newsite.su/$1$is_args$args; }
    }


But now the root folder is not redirected. That is, if we score, http://site.ru/forum/viewforum.php?f=4then we get to http://newsite.ru/viewforum.php?f=4, and if we simply score http://site.ru/by, we get a 404 error.
Question:
How to make it so that when a request
http://site.ru/forum/viewforum.php?f=4
is redirected to
http://newsite.ru/viewforum.php?f=4
and at the same time when a request
http://site.ru/всё_что_угодно(EXCEPT - the forum) is
redirected to
http://newsite.ru/
Thank you so much for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wostex, 2017-04-25
@D9910099

Try like this

server {
        listen       80;
        server_name  site.ru;
        location ~ ^/forum/(.*)$ {
          return 301 http://newsite.su/$1$is_args$args; 
        }

        location / {
          return 301 http://newsite.su/; 
        }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question