nginx在URL中使用斜线redirect

我正在为我们的营销工作做一个RYO QR代码pipe理系统,让所有的QR码打到指定的url结构,然后我将通过nginx转发到他们指定的地点。

我试图build立这样的结构:

server { listen 80; server_name mydomain.com/c/m/b/1; return 301 $scheme://myotherdomain.com$request_uri; } 

当我启动nginx时,我的服务器名称被调出来,因为有可疑的字符。 是否有可能在域名中使用斜杠?

这是基于猜测你可能想要的。

如果您想将所有http://mydomain.com/urlredirect到http://myotherdomain.com/ ,您应该这样做:

 server { listen 80; server_name mydomain.com; rewrite ^ http://myotherdomain.com$request_uri permanent; } 

如果您只想在某个path中redirect,则可以使用location指令:

 server { listen 80; server_name mydomain.com; location /c { rewrite ^ http://myotherdomain.com$request_uri permanent; } } 

否,斜杠不是域名的有效部分,或者不能用于分隔path和URL的协议部分(http: // )。

查看server_name config语句的扩展参数(regexes)是否有帮助。