[英]Rewrite a URL in nginx without redirecting
I'm trying to create a rewrite with nginx that will change the displayed URL without actually redirecting to it. 我正在尝试使用nginx创建重写,它将更改显示的URL,而无需实际重定向到它。 EG:
http://example.com/item/rest-of-path
would become http://example.com/folder/rest-of-path
. EG:
http://example.com/item/rest-of-path
: http://example.com/item/rest-of-path
将变为http://example.com/folder/rest-of-path
。 I've been working with different variations of this code with in my nginx.conf: 我一直在nginx.conf中处理此代码的不同变体:
location ~ /example {
rewrite ^/example/(.*) /folder/$1 last;
}
but that doesn't seem to be doing the trick. 但这似乎并不能解决问题。 Any ideas where I'm going wrong here?
有什么想法我要在这里出错吗? I'll admit I'm still pretty new to server-side rewrites in general.
我承认,对于服务器端重写而言,我还是很新的。
Try this: 尝试这个:
location ~ /example {
rewrite ^/example/(.*) /folder/$1 break;
}
use break
. 使用
break
。
Try this. 尝试这个。 It isn't necessary to place it under the
location
block, and don't forget to reload nginx. 不必将其放置在
location
块下,并且不要忘记重新加载nginx。
rewrite ^/example/(.+)$ /folder/$1 last;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.