当前位置: 首页 > nginx, OpenSource > 正文

nginx dynamic url rewrite — II

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

本文固定链接: https://www.2hei.net/2010/11/25/nginx_dynamic_url_rewrite_ii/ | 2hei.net

该日志由 u2 于2010年11月25日发表在 nginx, OpenSource 分类下,
原创文章转载请注明: nginx dynamic url rewrite — II | 2hei.net
关键字:

报歉!评论已关闭.