存档

2010年11月 的存档

nginx dynamic url rewrite — II

2010年11月25日 评论已被关闭
nginx rewirte II, nginx if has no AND OR and nest,so we only can use regx to do it:
———————————- BEGIN—————————————–
location /music/search.html {
root   /home/2hei.net/music;
if ($query_string ~* ^p=(.*)&a=(.*)&t=(.*)$) {
set $p $1;
set $a $2;
set $t $3;
rewrite /music/search.html http://www.last.fm/music/$p/$a/$t? last;
}
if ($query_string ~* ^p=(.*)&t=(.*)$) {
set $p $1;
set $t $2;
rewrite /music/search.html http://www.last.fm/music/$p/_/$t? last;
}
if ($query_string ~* ^p=(.*)&a=(.*)$) {
set $p $1;
set $a $2;
rewrite /music/search.html http://www.last.fm/music/$p/$a? last;
}
if ($query_string ~* ^p=(.*)$) {
set $p $1;
rewrite /music/search.html http://www.last.fm/music/$p? last;
}
rewrite /music/search.html http://www.last.fm/music/? last;
}
———————————- END —————————————–
Test URL:
http://2hei.net/music/search.html?p=lady gaga
http://2hei.net/music/search.html?p=lady gaga&a=the frame
http://2hei.net/music/search.html?p=lady gaga&t=just dance
http://2hei.net/music/search.html?p=lady gaga&a=the frame&t=just dance
分类: nginx, OpenSource 标签: