[英]nginx - manipulate request_uri while redirecting
I would like to know how to manipulate request_uri in my nginx config. 我想知道如何在我的nginx配置中操作request_uri。
I am trying to redirect all traffics with uri domain1.com/post/{slug}
to domain2.com/blog/{slug}
. 我正在尝试使用uri domain1.com/post/{slug}
将所有流量重定向到domain2.com/blog/{slug}
。
Currently, I set up the following: 目前,我设置了以下内容:
server {
listen 80;
server_name domain1.com;
return 301 $scheme://domain2.com/blog$request_url;
}
But the problem is domain1.com/post/{slug}
is redirected to domain2.com/blog/post/{slug}
, rather than domain2.com/blog/{slug}
. 但问题是domain1.com/post/{slug}
被重定向到domain2.com/blog/post/{slug}
,而不是domain2.com/blog/{slug}
。
How can I proceed from here? 我怎么能从这里开始?
Use a rewrite ... permanent
statement rather than the return
statement. 使用rewrite ... permanent
语句而不是return
语句。
rewrite ^/post(.*)$ $scheme://domain2.com/blog$1 permanent;
return 404;
Replace the return 404
with whatever the default case should be for URIs which do not begin with /post
. 对于不以/post
开头的URI,应该使用默认情况替换return 404
。
See this document for details. 请参阅此文档了解详细信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.