thinkphp6多应用模式下访问路由显示路由不匹配的解决方法
2022-11-24 11:10:29
205
{{single.collect_count}}

各位客官,欢迎光临小弟网站:maliweb.top

 

thinkphp6多应用模式下访问路由显示路由不匹配的解决方法:


问题描述:

[0]RouteNotFoundException in Route.php line 799当前访问路由未定义或不匹配if (false === $result && !empty($this->cross)) {// 检测跨域路由$result = $this->cross->check($this->request, $url, $completeMatch);}if (false !== $result) {return $result;} elseif ($this->config['url_route_must']) {throw new RouteNotFoundException();}return $this->url($url);}/** * 获取当前请求URL的pathinfo信息(不含URL后缀) * @access protected * @return string

解决方法:

(1)方法一:

在public目录下,复制index.php文件,针对每一个应用分别新建文件:例如:
现有admin应用,新建一个admin.php文件,复制index.php的内容然后修改其中的

$response = $http->name('admin')->run();name 对应你的应用名称

然后访问的时候,把把以前的index.php换成对用应用的文件,例如:
以前访问默认应用的路径为

域名/index.php/index

访问其他应用的路径,比如上面的admin应用为

域名/admin.php/idnex

(2)方法二:
自动多应用模式下,支持应用的别名映射,例如:

'app_map' => ['think'=>'admin',// 把admin应用映射为think],

应用映射后,原来的应用名将不能被访问,例如上面的admin应用不能直接访问,只能通过think应用访问。

应用映射支持泛解析,例如:

'app_map' => ['think' =>'admin','home'=>'index','*' =>'index',],

表示如果URL访问的应用不在当前设置的映射里面,则自动映射为index应用。

如果要使用composer加载应用,需要设置

'app_map'=>['think' => function($app) {$app->http->path('path/to/composer/app');},],

域名绑定应用
如果你的多应用使用多个子域名或者独立域名访问,你可以在config/app.php配置文件中定义域名和应用的绑定。

'domain_bind' => ['blog'=>'blog',//blog子域名绑定到blog应用'shop.tp.com' =>'shop',//完整域名绑定'*' =>'home', // 二级泛域名绑定到home应用],

 

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}