php自定义路由首页代码:
<?php echo '<pre>'; //var_dump($_SERVER); $route_ok = false; /*设置register_argc_argv = On(默认是Off),重启服务 $_SERVER[‘argv’]才会有效果*/ if(isset($_SERVER['argv']) && !isset($_SERVER['REQUEST_URI'])){ $url = urldecode($_SERVER['argv'][1]); }else{ $url = urldecode($_SERVER['REQUEST_URI']); } echo $url; echo '<br>=====<br>'; $open_urlroute=true; //伪静态开关 if($open_urlroute){ $open_url_route = include ('route.php'); //http://www.b.com/luyou/ $urls = '';// /luyou/ foreach($open_url_route as $k=>$v){ if($v!='' && $v[0]!='' && $v[1]!=''){ echo $route_ok = preg_match_all($v[0],$url,$matches);//匹配到为1 echo '<br>======route_ok=====<br>'; echo $urls = $v[1];// test/id/1 echo '<br>=====urls=====<br>'; echo $method = strtoupper($v[2]);//GET POST方式 echo '<br>=====<br>'; if($route_ok){ break; } } } if($route_ok){ //print_r($matches); foreach($matches as $k=>$v){ $urls = str_replace('$'.$k,$v[0],$urls); } echo $url = $urls; } //http://www.b.com/luyou/index.php?id=aa&b=4 $position = strpos($url,'?'); if($position!==false){ echo ' ||| '.$param = substr($url,$position+1); parse_str($param,$_GET);//将“id=aa&b=4”转成数组放在$_GET里面 var_dump($_GET); /* array(2) { ["id"]=>string(2) "aa" ["b"]=>string(1) "4" } */ } }else{ $open_url_route = []; }
route.php代码:
return [ /** ['正则url','系统内真实链接','传输方式POST/GET,或者为空,则表示POST/GET都接收'] 如果有多条匹配,默认第一条有效 demo: ['/\/base\/([0-9]+)\.html$/','Home/test/id/$1','GET'], ['/\/xbase\/([0-9]+)\/(\w+)\.html$/','Home/test/id/$1/sq/$2','POST'], ['/\/test_([0-9]+)\.html$/','Home/test/id/$1','GET'], ['/\/abc\.html$/','/shangpin.html',''], **/ //以下规则不可删除,否则会报错! //http://demo.jizhicms.cn/Home/screen/molds/product/categories/3 ['/^\/luyou\/(.*)/','test/id/$1','POST'], ['/^\/screen-(\w+)-([0-9]+)-(.*)/','Screen/index/molds/$1/tid/$2/jz_screen/$3',''], ['/^\/searchAll(.*)/','Home/searchAll','GET'], ['/^\/search(.*)/','Home/search','GET'], ];
php自定义路由结束
继续阅读与本文标签相同的文章
上一篇 :
php生成百度sitemap.xml
下一篇 :
php格式化时间格式
-
阿里云Linux服务器动态扩容(阿里云服务器扩容后磁盘空间无变化解决方法)
2020-11-30栏目: 建站教程
-
6个SEM实战技巧,大神手把手教你做推广!
2020-07-20栏目: SEM
-
苏州美食推荐,持续更新
2020-06-17栏目: 生活笔记
-
企业如何玩转视频号
2020-05-12栏目: 运营杂谈
-
SEO关键词排名该掌握的核心优化技巧
2020-05-12栏目: SEO
打印
分享
发表评论 已发布 0 条