Nginx重写最后不起作用

时间:2013-05-03 15:01:04

标签: nginx

我有重写网址的问题。永久工作正常。但是当我改为最后 - 它不起作用。 phpinfo显示旧值。

http://site.com/?parent_id=10 - > http://site.com/parent/10

if ($args ~ "parent_id=(.*)") {
  set $parent $1;
  set $args '';
  rewrite ^/$ /parent/$parent permanent;
}

它应该是内部的,因为将来的重写会将/ parent / 10转换为Yii框架URL规则。 我重写了旧网站以使用YiiFramework,并希望保留原来的旧网址。

谢谢,Alex

1 个答案:

答案 0 :(得分:1)

使用IF IS EVIL。附件是一些URL重写。同时删除set等..不需要字符串!

http://site.com/notes/343
http://site.com/note.php?id=343

rewrite ^/notes/(.*)$ /notes.php?id=$1 last;

http://site.com/users/BlackBenzKid
http://site.com/user.php?id=1

rewrite ^/users/(.*)$ /user.php?username=$1 last;

http://site.com/top
http://site.com/top.php

rewrite ^/top?$ /top.php last;

Complex and further

http://site.com/users/BlackBenzKid/gallery
http://site.com/user.php?username=1&page=gallery

rewrite ^/users/(.*)$/gallery /user.php?username=$1&page=gallery last;

回答您的问题。你想要的东西:

rewrite ^/parent/(.*)$ /parent.php?id=$1 permanent;