【问题标题】:Nginx & url rewritingNginx & url 重写
【发布时间】:2015-06-18 01:11:00
【问题描述】:

我有一个重定向:

server {
    server_name     mydomain.com;
    rewrite ^(.*)   http://myanotherdomain.net/image$1 permanent;
}

当我进入 mydomain.com/example 时一切正常,但是如何将 mydomain.com 指向我想要的位置?

我想要: mydomain.com/test -> myanotherdomain.net/image/test(或“test”以外)和 mydomain.com -> myanotherdomain.net

有可能吗?

【问题讨论】:

  • 所以您希望除根请求之外的所有内容都重定向到/image/

标签: nginx url-rewriting rewrite


【解决方案1】:
server {
    server_name mydomain.com;
    location = / {
        return 301 http://myanotherdomain.net;
    }
    location / {
        return 301 http://myanotherdomain.net/image$request_uri;
    }
}

【讨论】:

    猜你喜欢
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    • 2016-02-07
    • 2014-05-18
    • 2011-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多