nginx 重写而不更改 url [英] nginx rewrite WITHOUT change url
问题描述
我想在我的 nginx 服务器中使用重写功能.
I want to use rewrite function in my nginx server.
当我尝试http://www.example.com/1234"时,我想重写http://www.example.com/v.php?id=1234" 并希望获得 "
When I try "http://www.example.com/1234", I want to rewrite "http://www.example.com/v.php?id=1234" and want to get "http://www.example.com/1234" in browser.
这里是 nginx.conf 文件
Here is nginx.conf file
...
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
但是我遇到了麻烦......
but I'm in trouble ...
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://开头,则客户端将被重定向,并且任何进一步的 >rewrite 指令都会终止.
If the replacement string begins with http:// then the client will be redirected, and any further >rewrite directives are terminated.
所以删除 http://部分,它应该可以工作:
So remove the http:// part and it should work:
location ~ /[0-9]+ {
rewrite "/([0-9]+)" /v.php?id=$1 break;
}
这篇关于nginx 重写而不更改 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!