墨裔 发表于 2020-6-26 18:50:48

nginx伪静态规则


      在location / {}里添加,如:      location / {
            root   D:/phpweb/wwwroot;
            indexindex.php index.html index.htm;
            rewrite ^(.*)/t(\d+)\.html$ $1/index.php?t=3 last;
      }  仔细观察 rewrite ^(.*)/t(\d+)\.html$ $1/index.php?t=3 last;其实感觉nginx的伪静态规则蛮好写的。就是用正则的基础上,一个rewrite来声明,然后^是伪静态规则开头,(.*)匹配任意字符,这里匹配的就是域名了,t就是你在这里想加的字符,如你可以加apple、orange这样的分类名了,(\d+)匹配的是数字,\.html匹配的是后缀,$就是正则匹配的结束。后面半部分就是要改写的url了,用$1打头,表示域名,/index.php?t=3就是要改写的URL,用last;结束即可。
页: [1]
查看完整版本: nginx伪静态规则