Home >Backend Development >PHP Tutorial >nginx rewrite rule

nginx rewrite rule

WBOY
WBOYOriginal
2016-06-23 13:45:221487browse

实现下面的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;                }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn