nginx伪静态规则配置

#网上很多关于伪静态的配置,我只想说"楼主的是亲测"
#根据楼主的教程来nginx的伪静态规则配置,不成功的话,直播***!!!
背景,http://www.abc.com/index.php/front/index/parse?name=yangxignyi&age=18
这样的url很难看吧,处女座程序猿怎么会容忍这样的事情发生的呢?
http://www.abc.com/parse-yangxignyi-18.html这样的还差不多。

学会了这两条规则配置,nginx的伪静态规则配置基本就大专毕业了,哈哈哈哈…
场景一:
http://www.abc.com/index.php/front/index/index
重写成 http://www.abc.com/a.html

场景二:把带参数的1.2解析成3
1.http://www.abc.com/index.php/front/index/parse/name/yangxignyi/age/18
2.http://www.abc.com/index.php/front/index/parse?name=yangxignyi&age=18
3.http://www.abc.com/parse-yangxignyi-18.html
服务器配置文件:

server{
        listen       80;
        server_name  www.abc.com;
        root   "D:/phpStudy/WWW/abc";
        location / {
            index  index.php index.htm /public/index.html;
            autoindex  off;
			include abc.conf;
			#rewrite a.html /index.php/front/index/index 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;
        }
    }

伪静态配置文件可以直接写在 location / {} 里面的,不推荐这样做,建议新增加个rewrite.conf写伪静态文件会好点,include 进来就行了,这样可以在rewrite.conf里面写n多配置

location / {
            index  index.php index.htm /public/index.html;
            autoindex  off;
			include rewrite.conf;
			#rewrite a.html /index.php/front/index/index last;
        }

#rewrite.conf (这个文件自己创建就行了,文件内容写规则)

#场景一的规则
#http://www.abc.com/index.php/front/index/index
rewrite a.html /index.php/front/index/index last;

#场景二的规则
#1.http://www.abc.com/index.php/front/index/parse/name/yangxignyi/age/18
#2.http://www.abc.com/index.php/front/index/parse?name=yangxignyi&age=18
#3.http://www.abc.com/parse-yangxingyi-18.html
rewrite parse-(\w+)-(\d+).html /index.php/front/index/parse/name/$1/age/$2 last;

相信看过正则的同学都知道\w+和\d+是什么意思的吧,\w是数字字母下划线的意思,\d是数字的意思 +是最少一个{1,} 1到无穷大{1,3} 这样是1-3位数,关于正则这里就不多介绍啦,看下正则就知道了哦 !!!

写完规则,记得重启nginx,才能去吃饭哦!!!


  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值