NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
lijinma
V2EX  ›  NGINX

Nginex设置部分rewrite没成功,求大侠帮忙。。。感谢

  •  
  •   lijinma · Jan 24, 2014 · 3810 views
    This topic created in 4498 days ago, the information mentioned may be changed or developed.
    要做的事情:

    我想让网站"部分"域名跳转到新网站,其他不跳转:



    我的方法:
    listen 80;
    server_name www.old.com

    location / {
    rewrite ^/$ http://www.new.com/ permanent;
    rewrite ^/some_link/$ http://www.new.com/some_new permanent;
    rewrite ^/some_link/$ http://www.new.com/some_new permanent;
    ...


    问题:

    现在其他"不打算跳转的页面",打开后,全部是404


    大侠,求助。。。。应该是很简单的问题,在你的眼里。。
    14 replies    1970-01-01 08:00:00 +08:00
    lijinma
        1
    lijinma  
    OP
       Jan 24, 2014
    nginx还打错了。。。
    heyli
        2
    heyli  
       Jan 24, 2014
    if ($host ~* domain){
    rewrite ^/some_link/$ http://www.new.com/some_new permanent;
    }
    加多个$host 判断下
    bingu
        3
    bingu  
       Jan 24, 2014
    既然你只是想把部分链接301
    那第一条的作用是什么呢?

    rewrite ^/$ http://www.new.com/ permanent;

    去掉看看。
    lijinma
        4
    lijinma  
    OP
       Jan 24, 2014
    @bingu 首页也要301。。。
    lijinma
        5
    lijinma  
    OP
       Jan 24, 2014
    @heyli

    感谢兄弟,

    我明白你的意思,但是这个host下,没有rewrite的网页还是404..
    shiniv
        6
    shiniv  
       Jan 24, 2014
    我觉得首页可以直接在网页用header转跳就得了
    然后其他的就在nginx重定向
    xiaop
        7
    xiaop  
       Jan 24, 2014 via iPad
    既然301成功了,就说明404和这几条规则无关。
    pubby
        8
    pubby  
       Jan 24, 2014
    没rewrite 的会进入该server { ... } 的其他配置流程啊

    你应该反过来,可能更容易排查

    先让 www.old.com 正常访问,然后 加rewrite让部分条件301到新域名
    lijinma
        9
    lijinma  
    OP
       Jan 26, 2014
    @shiniv 有道理,我试一下 多谢
    lijinma
        10
    lijinma  
    OP
       Jan 26, 2014
    @xiaop 谢谢xiaop, 现在的情况是,去掉这几条规则,就没有404 =。=
    lijinma
        11
    lijinma  
    OP
       Jan 26, 2014
    @pubby 多谢 pubby,现在是其他配置应该怎么写?
    extreme
        12
    extreme  
       Jan 27, 2014
    试试这样
    location / {
    rewrite ^/$ http://www.new.com/ permanent;
    }
    location /some_link {
    rewrite ^/some_link/$ http://www.new.com/some_link permanent;
    }
    extreme
        13
    extreme  
       Jan 27, 2014
    上面回复的纠正一下:
    location /some_link {
    rewrite ^/some_lin(k|k/)$ http://www.new.com/some_link permanent;
    }
    lijinma
        14
    lijinma  
    OP
       Jan 27, 2014
    @extreme 多谢大侠,我试一下啊啊啊 :)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3227 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 11:02 · PVG 19:02 · LAX 04:02 · JFK 07:02
    ♥ Do have faith in what you're doing.