[英]DigitalOcean - How to route website.net traffic to website.com except for one page?
In DigitalOcean, we have all website.net
pointing all traffic to website.com
. 在DigitalOcean中,我们所有的website.net
将所有流量都指向了website.com
。 Anyone accessing the .net
will be redirected to .com
访问.net
任何人都将被重定向到.com
We have a scenario where we want the above to remain intact, but we want just one page to be loaded on the .net
and not be redirected to the .com
我们有一种情况,我们希望上述内容保持不变,但我们只希望将一个页面加载到.net
,而不将其重定向到.com
website.net/reset
should be accessible without any redirect happening to .com
but we're not really sure how to do that, as it's an edge case we're solving where this is the only solution at the moment. website.net/reset
应该可以访问,而不会对.com
进行任何重定向,但是我们不确定如何做到这一点,因为这是一个极端的情况,我们正在解决目前唯一的解决方案。
Any idea how to make website.net/reset
not redirect to website.com
using DigitalOcean? 知道如何使用DigitalOcean使website.net/reset
不重定向到website.com
吗?
UPDATE: 更新:
Nginx configuration for .net
.net
Nginx配置
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.website.net;
# Match /reset request exactly and redirect
location /reset {
# Redirect /reset to google does not work, redirects to website.com instead
# return 301 http://google.com/;
# Redirect /reset to website.net/reset does not work, redirects to website.com instead
return 301 http://www.website.net/reset;
}
# Redirect .net to .com
return 301 https://www.website.com$request_uri;
...
}
Added DNS for .com
/ .net
and nginx configuration for .net
, but still website.net/reset
redirects to website.com
. 新增DNS为.com
/ .net
和nginx的配置.net
,但仍website.net/reset
重定向到website.com
。 Any idea how to change this so it goes to website.net/reset
and not redirect to website.com
? 知道如何更改此设置,使其转到website.net/reset
而不重定向到website.com
吗?
The easiest way to do that would probably be to update the server configuration for the .net server to issue a 301 redirect response to the .com address for everything except website.com/reset. 最简单的方法可能是更新.net服务器的服务器配置,以对除website.com/reset以外的所有内容发出对.com地址的301重定向响应。 The details of this would depend on which web server you are using, eg nginx, apache, etc. 具体细节取决于您所使用的Web服务器,例如nginx,apache等。
For Apache this could be done using the RedirectMatch directive: 对于Apache,可以使用RedirectMatch指令来完成:
<VirtualHost digitaloceanwebsite.net:80>
ServerName digitaloceanwebsite.net
# Respond with a 301 redirect to all requests not made to /reset, /other, or /different/page
RedirectMatch permanent ^(?!\/reset$|\/other$|\/different\/page$) http://digitaloceanwebsite.com
DocumentRoot "/srv/http/digitaloceanwebsite/net"
<Directory "/srv/http/digitaloceanwebsite/net">
...
</Directory>
</VirtualHost>
<VirtualHost digitaloceanwebsite.com:80>
ServerName digitaloceanwebsite.com
DocumentRoot "/srv/http/digitaloceanwebsite/com"
<Directory "/srv/http/digitaloceanwebsite/com">
...
</Directory>
</VirtualHost>
If your websites are hosted on separate servers, just make sure that the website.net server has the RedirectMatch in its config. 如果您的网站托管在单独的服务器上,则只需确保website.net服务器的配置中具有RedirectMatch。
Update response: 更新响应:
Looking at the nginx config that you posted, it looks like the 301 return in the server block is taking precedence over the location block. 查看您发布的nginx配置,看起来服务器块中的301返回优先于位置块。
This nginx config should work for what you want to do. 这个nginx配置应该可以满足您的需求。
server {
...
server_name www.website.net;
# = specifies that this is an exact match which immediately takes precedence
location = /reset {
# location block for www.website.net/reset
}
# redirects all other requests
location / {
return 301 https://www.website.com$request_uri;
}
}
Also, if you need to add other exceptions or just want to do some further reading on this, this page at Digital Ocean has a good explanation of how nginx selects which location and server block to use. 另外,如果您需要添加其他例外或只是想对此做进一步的阅读,那么Digital Ocean上的此页面将很好地说明nginx如何选择要使用的位置和服务器块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.