V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
lijinma
V2EX  ›  NGINX

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

  •  
  •   lijinma · 2014-01-24 15:51:51 +08:00 · 3117 次点击
    这是一个创建于 3748 天前的主题,其中的信息可能已经有所发展或是发生改变。
    要做的事情:

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



    我的方法:
    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 条回复    1970-01-01 08:00:00 +08:00
    lijinma
        1
    lijinma  
    OP
       2014-01-24 16:01:55 +08:00
    nginx还打错了。。。
    heyli
        2
    heyli  
       2014-01-24 16:10:56 +08:00
    if ($host ~* domain){
    rewrite ^/some_link/$ http://www.new.com/some_new permanent;
    }
    加多个$host 判断下
    bingu
        3
    bingu  
       2014-01-24 16:22:48 +08:00
    既然你只是想把部分链接301
    那第一条的作用是什么呢?

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

    去掉看看。
    lijinma
        4
    lijinma  
    OP
       2014-01-24 16:46:05 +08:00
    @bingu 首页也要301。。。
    lijinma
        5
    lijinma  
    OP
       2014-01-24 17:37:37 +08:00
    @heyli

    感谢兄弟,

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

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

    先让 www.old.com 正常访问,然后 加rewrite让部分条件301到新域名
    lijinma
        9
    lijinma  
    OP
       2014-01-26 10:09:02 +08:00
    @shiniv 有道理,我试一下 多谢
    lijinma
        10
    lijinma  
    OP
       2014-01-26 10:09:50 +08:00
    @xiaop 谢谢xiaop, 现在的情况是,去掉这几条规则,就没有404 =。=
    lijinma
        11
    lijinma  
    OP
       2014-01-26 10:10:40 +08:00
    @pubby 多谢 pubby,现在是其他配置应该怎么写?
    extreme
        12
    extreme  
       2014-01-27 01:02:15 +08:00
    试试这样
    location / {
    rewrite ^/$ http://www.new.com/ permanent;
    }
    location /some_link {
    rewrite ^/some_link/$ http://www.new.com/some_link permanent;
    }
    extreme
        13
    extreme  
       2014-01-27 01:06:26 +08:00
    上面回复的纠正一下:
    location /some_link {
    rewrite ^/some_lin(k|k/)$ http://www.new.com/some_link permanent;
    }
    lijinma
        14
    lijinma  
    OP
       2014-01-27 09:43:47 +08:00
    @extreme 多谢大侠,我试一下啊啊啊 :)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5524 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 08:59 · PVG 16:59 · LAX 01:59 · JFK 04:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.