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

2014-01-24 15:51:51 +08:00
 lijinma
要做的事情:

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



我的方法:
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


大侠,求助。。。。应该是很简单的问题,在你的眼里。。
3128 次点击
所在节点    NGINX
14 条回复
lijinma
2014-01-24 16:01:55 +08:00
nginx还打错了。。。
heyli
2014-01-24 16:10:56 +08:00
if ($host ~* domain){
rewrite ^/some_link/$ http://www.new.com/some_new permanent;
}
加多个$host 判断下
bingu
2014-01-24 16:22:48 +08:00
既然你只是想把部分链接301
那第一条的作用是什么呢?

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

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

感谢兄弟,

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

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

先让 www.old.com 正常访问,然后 加rewrite让部分条件301到新域名
lijinma
2014-01-26 10:09:02 +08:00
@shiniv 有道理,我试一下 多谢
lijinma
2014-01-26 10:09:50 +08:00
@xiaop 谢谢xiaop, 现在的情况是,去掉这几条规则,就没有404 =。=
lijinma
2014-01-26 10:10:40 +08:00
@pubby 多谢 pubby,现在是其他配置应该怎么写?
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
2014-01-27 01:06:26 +08:00
上面回复的纠正一下:
location /some_link {
rewrite ^/some_lin(k|k/)$ http://www.new.com/some_link permanent;
}
lijinma
2014-01-27 09:43:47 +08:00
@extreme 多谢大侠,我试一下啊啊啊 :)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/98222

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX