1. 程式人生 > >TP5多入口設置

TP5多入口設置

oot mes root art rewrite con min () nginx

今天在用tp5做項目的時候發現,前臺是可以綁定默認到index模塊的,但是後臺不好弄,於是查了一下手冊,按照手冊上說的,復制了index.php改為admin.php,作為後臺的入口文件,於是域名/admin.php就可以訪問後臺了(默認是admin模塊的index控制器的index方法),雖然可以訪問了,但是我是個完美主義者,或者說室友強迫癥的人,我覺得admin.php的.php看上去很是刺眼,要是能去掉就更好了,於是我就想到了把nginx的配置改一下,抱著試一試的態度,結果還是挺滿意的,去掉了尾巴看上去爽多了,下面貼上代碼

入口文件admin.php

 1 <?php
 2 // +----------------------------------------------------------------------
3 // | ThinkPHP [ WE CAN DO IT JUST THINK ] 4 // +---------------------------------------------------------------------- 5 // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved. 6 // +---------------------------------------------------------------------- 7 // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8 // +---------------------------------------------------------------------- 9 // | Author: liu21st <[email protected]> 10 // +---------------------------------------------------------------------- 11 12 // [ 應用入口文件 ] 13 14 // 定義應用目錄 15 define(‘APP_PATH‘, __DIR__ . ‘/../application/‘); 16 // 綁定到admin模塊 17
define(‘BIND_MODULE‘,‘admin‘); 18 // 加載框架引導文件 19 require __DIR__ . ‘/../thinkphp/start.php‘; 20 21 ?>

後臺首頁Index.php

 1 <?php
 2 /*
 3 *功能:後臺首頁控制器
 4 *作者:魏安來
 5 *日期:2017/12/12
 6 */
 7 
 8 namespace app\admin\controller;
 9 
10 class Index extends Base{
11 
12     /*後臺首頁*/
13     public function index(){
14         return ‘admin‘;
15         //return $this->fetch();
16     }
17 
18 }
19 
20 ?>

nginx配置vhosts.conf

 1 server {
 2         listen       80;
 3         server_name  www.tpmall.com tpmall.com;
 4         root   "F:/phpStudy/WWW/tpmall/public";
 5         location / {
 6             index  index.html index.htm index.php admin.php;
 7             #autoindex  on;
 8             
 9           if (!-e $request_filename){
10               rewrite  ^(.*)$  /index.php?s=/$1  last;
11           }
12           if (!-e $request_filename){
13               rewrite  ^(.*)$  /admin.php?s=/$1  last;
14           }
15 
16         }
17         location ~ \.php(.*)$ {
18             fastcgi_pass   127.0.0.1:9000;
19             fastcgi_index  index.php;
20             fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
21             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
22             fastcgi_param  PATH_INFO  $fastcgi_path_info;
23             fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
24             include        fastcgi_params;
25         }
26 }

TP5多入口設置