欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

nginx rewrite rule

程序员文章站 2022-05-04 09:54:17
...
实现下面的rewrite:
abc.domian.com/sort/2 => abc.domian.com/index.php?act=sort&name=abc&id=2

nginx.conf里面这么写是正确的吧:
rewrite ^/(.+)\/(\d+)\/?$ /index.php?act=$1&id=$2 last;


回复讨论(解决方案)

基本可以确定你用的CI框架

if (\$request_uri !~ ^/(html|static|favicon/.ico|robots/.txt|index/.php.*) ) {                        rewrite ^/(.*)\$ /index.php/\$1 last;                        break;                }

上面那个是错误的
这个的意思是如果访问 html static等这些静态目录时直接返回,如果不是才需要路由到index.php

if ($request_uri !~ ^/(html|static|favicon/.ico|robots/.txt|index/.php.*) ) {                        rewrite ^/(.*)$ /index.php/$1 last;                        break;                }