Php 如何使用Nginx重定向到特定页面?

Php 如何使用Nginx重定向到特定页面?,php,redirect,nginx,Php,Redirect,Nginx,您好,我希望使用Nginx重定向到某个页面,例如: 当前域正在testing.example.com。I wana进入的页面是testing.example.com/test,但I wana重定向的域是t.example.com,因此: t、 example.com=testing.example.com/test 任何帮助,谢谢 添加您的t.example.com位置{}类似于: rewrite ^(.*) http://testing.example.com/test/$1 permanen

您好,我希望使用Nginx重定向到某个页面,例如: 当前域正在testing.example.com。I wana进入的页面是testing.example.com/test,但I wana重定向的域是t.example.com,因此:

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


任何帮助,谢谢

添加您的
t.example.com位置{}
类似于:

rewrite ^(.*) http://testing.example.com/test/$1 permanent;
或者只是简单的重定向

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

在主机配置的
服务器
块中尝试此操作

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

如果您只想重定向所有流量,请使用以下服务器块。如果您想连接uri,则可以在return语句中添加
$request\u uri

$scheme
用于在重定向到位置中保留
http
https
协议,否则您可以将其替换为任一协议,而无需使用
$scheme

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