重写url,但显示原始URL + nginx
问题描述:
我是nginx新手。 我正尝试使用nginx将页面(“example.com/randomText/abc”)重定向到页面(“example.com/abc”)。重写url,但显示原始URL + nginx
location ~ ^/(.*/abc){
#method 1
rewrite (.*) /abc break;
#method 2
#return 301 http://$host/abc;
#method 3
#proxy_pass http://$host/abc/;
#proxy_set_header Host $host;
#proxy_set_header X-Rewrite-URL $request_uri;
}
方法1和2工作,但它也改变URL为 “http://example.com/abc” 方法3返回用502错误。
答
你需要的是类似下面
location ~ ^/[^/]+/abc {
proxy_pass http://$host/abc;
}
它给502错误 –