【问题标题】:NGINX domain rewrite rulesNGINX 域重写规则
【发布时间】:2016-02-04 16:11:43
【问题描述】:

我想用 nginx 实现的是:

http://domain.com - redirects to http://otherdomain/page.html
http://www.domain.com - redirects to http://otherdomain/page.html
http://domain.com/* - redirects to http://otherdomain/*

基本上只有域名和 www 应该被重定向到一个 url 链接。其他所有内容都应重定向到另一个域,但保持 url 如下:

http://domain.com/subdomain/page.html -> http://otherdomain/subdomain/page.html

如果您有任何问题,请告诉我。谢谢!

【问题讨论】:

    标签: mod-rewrite nginx url-rewriting rewrite


    【解决方案1】:

    你可以使用 $request_uri

    http://nginx.org/en/docs/varindex.html

    大概如下

    server{
       location = /
       {
           rewrite ^ http://otherdomain/page.html;
       }
       location /subdomain
       {
           rewrite ^ http://otherdomain/$request_uri;
       }
    }
    

    【讨论】:

    • 感谢您的重播。这可能有效,但实际上我需要别的东西,我想我无法清楚地解释它。所以它是这样的:domain.com/asadasdsad -> otherdomain/asadasdsad domain.com* -> otherdomain* 除了 domain.com 和 www.domain.com,我需要根据初始请求重写完整的 url。如果用户请求 page.html,它将重定向到第二个域 page.html。如果用户请求 subdomain/page.html,它将重定向到另一个域 subdomain/page.html。希望你明白我在寻找什么。
    猜你喜欢
    • 2015-04-04
    • 2011-01-16
    • 1970-01-01
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-04
    相关资源
    最近更新 更多