nginx重写无需更改url
问题描述:
我想在我的nginx服务器中使用重写功能。nginx重写无需更改url
当我尝试“http://www.example.com/1234”时,我想重写“http://www.example.com/v.php?id=1234”,并想在浏览器中获得“http://www.example.com/1234”。
这里是nginx.conf文件
...
location ~ /[0-9]+ {
rewrite "/([0-9]+)" http://www.example.com/v.php?id=$1 break;
}
...
当我尝试 “http://www.example.com/1234”
我想...
url bar in browser : http://www.example.com/1234
real url : http://www.example.com/v.php?id=1234
,但我有麻烦......
url bar in browser : http://www.example.com/v.php?id=1234
real url : http://www.example.com/v.php?id=1234
答
参考:http://wiki.nginx.org/HttpRewriteModule#rewrite
如果替换字符串以http://开头,则客户端将被重定向,并且任何其他>重写指令都将终止。
所以删除HTTP://部分,它应该工作:
location ~ /[0-9]+ {
rewrite "/([0-9]+)" /v.php?id=$1 break;
}