nginx配置url伪静态

  • rewrite 规则 定向路径 重写类型;
  • 举例: rewrite  (.*)/web/(.*)-(.*)-(.*).html$  $1/web/index.php?r=$2/$3/$4  last;   浏览器中输入http://test.com/web/api-test-index.html 会被nginx转化为http://test.com/web/index.php?r=api/test/index去请求服务器资源。
  • rewrite 后面的规则 (.*)/web/(.*)-(.*)-(.*).html$ 是匹配请求的路径的(即浏览器中输入的url),定向路径 $1/web/index.php?r=$2/$3/$4 是指服务器上的项目真实的路径,重写类型有多个,last,break,redirect,permanent,具体看nginx文档或戳这里
  • ()中匹配到的内容会被按顺序分配到变量$1 $2 $3  $4中,上面的正常来说就是$1匹配的是域名, $2匹配moduleID(这里是以yii的路由来说的),$3匹配controllerID, $4匹配actionID
  • 参考:https://blog.csdn.net/qq_25600055/article/details/78543614

猜你喜欢

转载自www.cnblogs.com/bneglect/p/12058464.html