如何详细改造PHP Workerman实现伪静态?

2026-05-07 20:141阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计265个文字,预计阅读时间需要2分钟。

如何详细改造PHP Workerman实现伪静态?

相关专题

if (in_array($workerman_file_extension,['php','html']) && !is_file($workerman_file)) { $workerman_file = "{$workerman_root_dir}/index.php"; $workerman_file_extension = 'php'; if (!is_file($workerman_file)) { $workerman_file = "{$workerman_root_dir}/index.html"; $workerman_file_extension = 'html'; } }

这样以后,只要访问扩展名为html的文件,且这个文件不存在,就会自动重定向到index.php,然后再在index.php进行判断就行了

二、index.php改造,输出页面前,增加以下判断:

//重定向判断 $uri=$_SERVER['REQUEST_URI']; $ext=strtolower(substr($uri,-4,4)); if(is_cli()&&$ext=='html'){ $_GET['_']=substr($uri,1,strlen($uri)-5); }

比如,我访问的地址是http://c.com/Users_login.html,即访问index.php?_=Users_login

立即学习“PHP免费学习笔记(深入)”;

三、根据$_GET['_'],分割下划线,判断加载哪一个类和类的方法,就行了。比如:

$_GET['_']=isset($_GET['_'])?$_GET['_']:strcode('Index_index'); $strs=strcode($_GET['_'],'DECODE'); if(!$strs)xdie('param error.'); $d=preg_split('/[\.\_]/',$strs); if(count($d)<2)xdie('error:param'); $class=$d[0].'Action'; $action=$d[1];

再加载类并运行就行了。

更多workerman知识请关注PHP中文网workerman教程栏目。

标签:PHPWorkerman

本文共计265个文字,预计阅读时间需要2分钟。

如何详细改造PHP Workerman实现伪静态?

相关专题

if (in_array($workerman_file_extension,['php','html']) && !is_file($workerman_file)) { $workerman_file = "{$workerman_root_dir}/index.php"; $workerman_file_extension = 'php'; if (!is_file($workerman_file)) { $workerman_file = "{$workerman_root_dir}/index.html"; $workerman_file_extension = 'html'; } }

这样以后,只要访问扩展名为html的文件,且这个文件不存在,就会自动重定向到index.php,然后再在index.php进行判断就行了

二、index.php改造,输出页面前,增加以下判断:

//重定向判断 $uri=$_SERVER['REQUEST_URI']; $ext=strtolower(substr($uri,-4,4)); if(is_cli()&&$ext=='html'){ $_GET['_']=substr($uri,1,strlen($uri)-5); }

比如,我访问的地址是http://c.com/Users_login.html,即访问index.php?_=Users_login

立即学习“PHP免费学习笔记(深入)”;

三、根据$_GET['_'],分割下划线,判断加载哪一个类和类的方法,就行了。比如:

$_GET['_']=isset($_GET['_'])?$_GET['_']:strcode('Index_index'); $strs=strcode($_GET['_'],'DECODE'); if(!$strs)xdie('param error.'); $d=preg_split('/[\.\_]/',$strs); if(count($d)<2)xdie('error:param'); $class=$d[0].'Action'; $action=$d[1];

再加载类并运行就行了。

更多workerman知识请关注PHP中文网workerman教程栏目。

标签:PHPWorkerman