问题描述
我没有运气在谷歌上搜索这个,也许是因为我使用了错误的术语.
I'm having no luck googling this, maybe because I'm using the wrong terminology.
以下是一些示例来阐明我正在寻找的行为:
Here are some examples to clarify the behavior I'm looking for:
重定向
- 主机名-两个.com ->主机名-两个.com/sub-folder
- hostname-two.com -> hostname-two.com/sub-folder
没有重定向
hostname-两个.com/something(URL 已经可以 url)
hostname-two.com/something (URL already ok url)
hostname-two.com/sub-folder(URL 已经可以 url)
hostname-two.com/sub-folder (URL already ok url)
hostname-two.com/sub-folder/something (URL 已经可以 url)
hostname-two.com/sub-folder/something (URL already ok url)
hostname-one.com(hostname-one 不应该受到影响)
hostname-one.com (hostname-one should not be affected)
hostname-one.com/something(hostname-one 不应该受到影响)
hostname-one.com/something (hostname-one should not be affected)
所以我认为不需要重写 URL,只需要重定向.
So I'm thinking no URL rewrites should be needed, only redirects.
我有一个响应 hostname-one.com 和 hostname-two.com 的服务器
I have a server that responds to hostname-one.com and hostname-two.com
这是通过两个具有不同 server_name
属性的服务器块实现的.
This is accomplished with two server blocks with different server_name
properties.
我曾尝试在 server
块中使用 location
块,该块具有 hostname-two.com 的 server_name
,但到目前为止我的尝试还没有'无法满足上述所有条件.
I have tried using location
blocks in the server
block that has the server_name
of hostname-two.com but my attempts so far hasn't been able to satisfy all the conditions above.
如果有人能指出我正确的方向,我将不胜感激!
I would be very grateful if someone could point me in the right direction!
推荐答案
您可以尝试在您的第二个服务器块中使用此位置:
You can try to use this location in your second server block:
location = / {
return 301 /sub-folder;
}
您仍然可以使用 location/{ ... }
块,它会处理任何其他请求:
You still can use location / { ... }
block, it will process any other request:
location = / {
return 301 /sub-folder;
}
location / {
...
}
这篇关于匹配特定主机名并重定向到 www.myhostname.com/some-extra-path,不影响其他主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!