简体   繁体   中英

How to use Nginx to redirect to specific page?

Hi am looking to use Nginx to redirect to a certain page for example: current domain is testing.example.com. The page I wana get to is testing.example.com/test but the domain i wana redirect from is t.example.com so:

t.example.com = testing.example.com/test

Any help thanks!

If all you want is to redirect all the traffic, use this following server block, if you want to concatenate the uri then you could add $request_uri in the return statement.

$scheme is used to preserve http and https protocols in the redirected-to location, otherwise you can replace it with either without using $scheme

server {
    server_name t.example.com;
    location / {
        return 301 $scheme://testing.example.com/test;
    }
}

add in your t.example.com location { } something like:

rewrite ^(.*) http://testing.example.com/test/$1 permanent;

or just simple redirect

return 301 http://testing.example.com/test/;

Try this in your server block of host configuration

location /test {
   rewrite ^ $scheme://testing.example.com$request_uri permanent;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM