我有这种情况。我想在 nginx 中以这种格式重定向所有子域。
(profile_name).mydomain.com mydomain.com/profile/(profile_name)
我如何在 nginx 中执行此操作?
谢谢。
最佳答案
您可以使用正则表达式 server
block 。
server {
server_name ~^(?<name>.+)\.example\.com$;
return 301 http://example.com/profile/$name$request_uri;
}
参见 this document了解详情。
关于redirect - 如何使用 uri 将动态子域重定向到域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34980663/