我想用nginx重写我的网址。
我的代码
location /test {
rewrite ^/test/(.*) /$1 last;
proxy_pass http://example.com;
}
完整网址如下所示:127.0.0.1/test/example.com
我希望删除 127.0.0.1/test/并将请求直接重定向到 example.com
有人可以帮忙吗?
尝试这个简单的永久重定向:
location /test {
return 301 http://example.com;
}
编辑:使用重定向规则,您可以执行以下操作:
rewrite ^/test/(.*)$ http://example.com/$1 redirect;
上面的重写规则分别重写了从/test/XYZ 或只是/test/ 到 http://example.com/ 到 https://example.com/XYZ 的所有内容。