今天在用tp5做項目的時候發現,前臺是可以綁定默認到index模塊的,但是后臺不好弄,于是查了一下手冊,按照手冊上說的,復制了index.php改為admin.php,作為后臺的入口文件,于是域名/admin.php就可以訪問后臺了(默認是admin模塊的index控制器的index方法),雖然可以訪問了,但是我是個完美主義者,或者說室友強迫癥的人,我覺得admin.php的.php看上去很是刺眼,要是能去掉就更好了,于是我就想到了把nginx的配置改一下,抱著試一試的態度,結果還是挺滿意的,去掉了尾巴看上去爽多了,下面貼上代碼
入口文件admin.php
?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st liu21st@gmail.com>
// +----------------------------------------------------------------------
// [ 應用入口文件 ]
// 定義應用目錄
define('APP_PATH', __DIR__ . '/../application/');
// 綁定到admin模塊
define('BIND_MODULE','admin');
// 加載框架引導文件
require __DIR__ . '/../thinkphp/start.php';
?>
后臺首頁Index.php
?php
/*
*功能:后臺首頁控制器
*作者:魏安來
*日期:2017/12/12
*/
namespace app\admin\controller;
class Index extends Base{
/*后臺首頁*/
public function index(){
return 'admin';
//return $this->fetch();
}
}
?>
nginx配置vhosts.conf
server {
listen 80;
server_name www.tpmall.com tpmall.com;
root "F:/phpStudy/WWW/tpmall/public";
location / {
index index.html index.htm index.php admin.php;
#autoindex on;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=/$1 last;
}
if (!-e $request_filename){
rewrite ^(.*)$ /admin.php?s=/$1 last;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
到此這篇關于TP5多入口設置實例講解的文章就介紹到這了,更多相關TP5多入口設置內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- PHP tp5中使用原生sql查詢代碼實例
- tp5.1 框架數據庫-數據集操作實例分析
- tp5.1 框架路由操作-URL生成實例分析
- tp5.1 框架join方法用法實例分析
- tp5.1框架數據庫子查詢操作實例分析
- tp5.1 框架數據庫常見操作詳解【添加、刪除、更新、查詢】