构建PHP路由器
可能重复:构建PHP路由器,php,url-routing,Php,Url Routing,可能重复: 我目前正试图重写一个PHP路由器 新的htaccess重写具有以下特点 <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule (.*) public/index.php?url=$1 [L] </IfModule> 重新启动发动机 重写规则^$public/[L] 重写规则(.*)public
我目前正试图重写一个PHP路由器 新的htaccess重写具有以下特点
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/index.php?url=$1 [L]
</IfModule>
重新启动发动机
重写规则^$public/[L]
重写规则(.*)public/index.php?url=$1[L]
在public
中的index.php中,我使用$URL=$\u GET['URL']获取URL代码>
我需要做的是将$url
传递给路由器函数::路由($url)
如果URL作为:/page/function/$params传递,然后转换为:index.php?URL=page/xapp/function
,我需要映射并路由到控制器xapp
,并调用函数($params)
此时,自动加载器已被调用。如果只调用了/page/,我还需要设置一个默认函数
如何在路由器中实现这一点?您应该查看一个小型php路由器的代码。
我认为你应该从这个解决方案中找到答案
如果没有,请同时查看slim,或者您也可以尝试此路由器软件包,