私人领地

thinkphp6多用用模式下缩短路由

场景描述:要做seo,要缩短路由。原xxx.com/home/article/1改为xxx.com/article/1

解决办法:index.php

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

// [ 应用入口文件 ]
namespace think;

require __DIR__ . '/../vendor/autoload.php';

// 项目位置
define('APP_PATH',dirname(__DIR__));
// WEB入口文件位置
define('PUBLIC_PATH','/public');
// 上传文件夹
define('UPLOAD','/uploads');
// 模板部署
define('TEMPLATE_PATH', 'template');

// 执行HTTP应用并响应
$http = (new App())->http;

// 关键在此处
$_amain = 'index';
$_aother = 'admin|common'; // 匹配此条件,就按照tp默认模式跑。否则就全部跑index应用
if (preg_match('/^\/('.$_aother.')\/?/', $_SERVER['REQUEST_URI'])) {
    $response = $http->run();
} else {
    //设置指定应用
    $response = $http->name($_amain)->run();
}

$response->send();

$http->end($response);

  

posted @ 2023-07-01 11:43  狂奔的蜗牛Snails  阅读(52)  评论(0编辑  收藏  举报