首先我们可以在本地测试!打开对应的.conf文件
以phpStudy为例 用nginx+php运行 对应配置文件在 phpStudy\nginx\conf\vhosts.conf 文件中
我们再中间加入这一句
rewrite ^/listbb.html$ /bb.html last;
好了
server { listen 198; server_name gangchang ; root "D:/phpStudy/WWW/new/san/"; location / { index index.html index.htm index.php; #autoindex on; } rewrite ^/listbb.html$ /bb.html last; location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } }
然后我们重启
再打开刚我们改的是198的端口
我们在root "D:/phpStudy/WWW/new/san/"; 目录下新建一个bb.html 然后再打开
localhost:198/listbb.html
我们就会发现打开的是bb.html内容了!
好了!方法以及出来了! 那么我们可以优化下!把改变的规则放入一个bb_nginx.conf文件中
下面是一份phpcms的正则规则! 正好最近做这个的迁移搞的!
rewrite ^/listbb-([0-9]+)-([0-9]+).html$ /bb.html?&s=$1&page=$2 last; rewrite ^/list-([0-9]+)-([0-9]+).html$ /index.php?m=content&c=index&a=lists&catid=$1&page=$2 last; rewrite ^/content-([0-9]+)-([0-9]+)-([0-9]+).html$ /index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3 last; rewrite ^/show([0-9]+)-([0-9]+)-([0-9]+).html$ /index.php?m=content&c=index&a=show&catid=$1&id=$2&page=$3 last; rewrite ^/tag-([^\.]*)-([0-9]+)-([0-9]+).html$ /index.php?m=content&c=tag&catid=$2&tag=$1&page=$3 last; rewrite ^/comment-([0-9]+)-([0-9]+)-([0-9]+).html$ /index.php?m=comment&c=index&a=init&commentid=content_$1-$2-$3 last;
然后我们在
server { .... .... include /.对应路径./bb_nginx.conf; }
server结尾前引入这个规则即可!然后重启!
好了! 具体规则配置可以去研究下正则!或者根据上面的进行修改即可!
和服务器同理!
在服务器找到对应的conf文件! 然后改完
重启web
重启web
重启web
不然不管用的!