nginx pathinfo 并隐藏index.php

173 server
174 {
175 listen  80;
176 server_name s.tongxinmao.com;
177 index index.htm index.html index2.php;
178 root /home/wwwroot/default/txm2;
179 
180 
181 location / {
182         index  index.htm index.html index2.php;
183         try_files  $uri  /index2.php$uri;
184 }
185 location ~ .+\.php($|/) {
186         fastcgi_pass unix:/dev/shm/php-cgi.sock;
187         fastcgi_index indexx2.php;
188         include fastcgi.conf;
189         fastcgi_split_path_info  ^(.+\.php)(/.*)$;
190         fastcgi_param  PATH_INFO $fastcgi_path_info;
191 }
192 

193 }



PHP中PATHINFO处理://默认控制器及方法 及参数$_GET转存


 function parseUrl(){
if (isset($_SERVER['PATH_INFO'])){
      //获取 pathinfo
$pathinfo = explode('/', trim($_SERVER['PATH_INFO'], "/"));

        // 获取 control
        $_GET['c'] = (!empty($pathinfo[0]) ? $pathinfo[0] : 'Index');
                    $this->c =$_GET['c'];


        array_shift($pathinfo); //将数组开头的单元移出数组 
     
      // 获取 action
        $_GET['a'] = (!empty($pathinfo[0]) ? $pathinfo[0] : 'Index');
        $this->a =$_GET['a'];
       
array_shift($pathinfo); //再将将数组开头的单元移出数组 




for($i=0; $i<count($pathinfo); $i+=2){
$_GET[$pathinfo[$i]]=$pathinfo[$i+1];
}

}else{
$_GET["c"]= (!empty($_GET['c']) ? $_GET['c']: 'Index');    //默认是index模块
$_GET["a"]= (!empty($_GET['a']) ? $_GET['a'] : 'Index');   //默认是index动作

if($_SERVER["QUERY_STRING"]){
$m=$_GET["c"];
unset($_GET["c"]);  //去除数组中的m
$a=$_GET["a"];
unset($_GET["a"]);  //去除数组中的a
$query=http_build_query($_GET);   //形成0=foo&1=bar&2=baz&3=boom&cow=milk格式
//组成新的URL
$url=$_SERVER["SCRIPT_NAME"]."/{$m}/{$a}/".str_replace(array("&","="), "/", $query);
header("Location:".$url);
}
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值