nginx的url重写案例

最近需要在nginx上url rewrite重写,需求如下:

http://{{host}}/app/lj_cps_shops/index
http://{{host}}/app/index.php?c=lj_cps_shops&m=index

需要将上边的转换为下边的样子

最后在正则在线测试的平台测试出来了
nginx的url重写案例_第1张图片

下边贴代码,在nginx的config文件中添加如下:

location /app {
	rewrite ^\/app\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\??(.*) /app/index.php?c=$1&m=$2&$3 last;
}

重启nginx成功
正则在线测试的地址:http://tool.oschina.net/regex/#

你可能感兴趣的:(linux)