T
T
tuxx2017-04-27 17:05:37
Nginx
tuxx, 2017-04-27 17:05:37

How to make a redirect from the main directory to the directory?

We set the task to make a redirect from one site to another. Only domains should change in addresses, but the main of the current site should redirect to a specific directory of the new site.
The config turned out like this:

server {
        listen  80;
        server_name  www.site.ru, site.ru;

        location = / {
                return 301 http://other-site.ru/newhome; # 301-redirect
                # или
                #rewrite ^ http://other-site.ru/newhome permanent; # 301-redirect
        }

        location / {
                rewrite ^ $scheme://other-site.ru$request_uri? permanent; #301-redirect
        }
}

Redirect from different pages works as it should. From the main site.ru it goes to other-site.ru, but it should go to other-site.ru/newhome. At the same time, it redirects from www.site.ru to other-site.ru/newhome

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2017-04-27
@tuxx

You are correct.
If something is wrong, the problem is most likely in the browser cache.

rewrite ^ $scheme://other-site.ru$request_uri? permanent; #301-redirect
Here ? not needed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question