问题
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:
Redirects for
- hostname-two.com -> hostname-two.com/sub-folder
No re-directs for
hostname-two.com/something (URL already ok url)
hostname-two.com/sub-folder (URL already ok url)
hostname-two.com/sub-folder/something (URL already ok url)
hostname-one.com (hostname-one should not be affected)
hostname-one.com/something (hostname-one should not be affected)
So I'm thinking no URL rewrites should be needed, only redirects.
Current setup
I have a server that responds to hostname-one.com and hostname-two.com
This is accomplished with two server blocks with different server_name properties.
What I have tried
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!
回答1:
You can try to use this location in your second server block:
location = / {
return 301 /sub-folder;
}
You still can use location / { ... } block, it will process any other request:
location = / {
return 301 /sub-folder;
}
location / {
...
}
来源:https://stackoverflow.com/questions/60551733/matching-specific-host-name-and-redirecting-to-www-myhostname-com-some-extra-pat