简体   繁体   English

DigitalOcean-如何将website.net流量路由到website.com(一页除外)?

[英]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: 更新:

DNS for .com .com DNS 在此处输入图片说明

DNS for .net .net DNS 在此处输入图片说明

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.

相关问题 NGINX 将 www.website.com/folder/ 重定向到 website.com - NGINX Redirect www.website.com/folder/ to website.com 除www.website.com以外的所有配置? - Catch-all configuration except for www.website.com? 托管在 Kubernetes (DigitalOcean) 上的网站的最佳实践 - Best practise for a website hosted on Kubernetes (DigitalOcean) 如果第一个站点关闭,我如何将流量路由到辅助站点? - How do I route traffic to a secondary site if first one is down? 如何将域名指向另一个网站的页面? - How to point a domain into another website's page? NGINX + CentOS 8 mydomain.com shows NGINX welcome page whereas mydomain.com/index.html shows website index page - NGINX + CentOS 8 mydomain.com shows NGINX welcome page whereas mydomain.com/index.html shows website index page 问题托管在网站的子路由处响应应用程序-多个网站一个IP地址NGINX - Problem hosting react app at sub route of website - multiple websites one IP address NGINX 高流量网站应使用哪种网络托管设置? - What web hosting setup should I use for high traffic website? 通过液滴 IP 访问网站(Digitalocean Droplet 中的 Laravel)正在工作,但使用注册域显示 404 - Accessing website(Laravel in Digitalocean Droplet) through the droplet IP is working, but using the registered domain is showing 404 如何制作像 hidester.com/proxy 这样的“网站内代理”? GitHub 上已经有这样的东西了吗? - How do I make an "in website proxy" like hidester.com/proxy? Is there anything already on GitHub like this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM