MVC框架自定义隐藏index.php入口文件伪静态

释放双眼,带上耳机,听听看~!

PHP:

public function initPath(){
        $path = $_SERVER['PATH_INFO'];
        $lastFix = strrchr($path,'.');
        $path = str_replace($lastFix,'',$path);
        $path = substr($path,1);
        $array = explode('/',$path);
        $lenght = count($array);
        if ($lenght == 1){
            $_GET['m'] = $array[0];
        }elseif ($lenght == 2){
            $_GET['m'] = $array[0];
            $_GET['c'] = $array[1];
        }elseif ($lenght == 3){
            $_GET['m'] = $array[0];
            $_GET['c'] = $array[1];
            $_GET['a'] = $array[2];
        }else{
            $_GET['m'] = $array[0];
            $_GET['c'] = $array[1];
            $_GET['a'] = $array[2];
            for ($i=3;$i<$lenght;$i+=2){
                $_GET[$array[$i]] = $array[$i+1];
            }
        }
    }

Nginx:

if (!-d $request_filename){
    set $rule_0 1$rule_0;
}
if (!-f $request_filename){
    set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
    rewrite /(.*) /index.php/$1;
}

Apache:

<IFModule rewrite_module>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule (.*) index.php/$1

</IFModule>

人已赞赏
知识分享

PHP并发场景的解决方案

2020-8-3 13:10:00

知识分享

Composer安装详解教程

2020-8-5 13:12:00

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索