TP5多入口设置实例讲解

2025-05-29 0 45

今天在用tp5做项目的时候发现,前台是可以绑定默认到index模块的,但是后台不好弄,于是查了一下手册,按照手册上说的,复制了index.php改为admin.php,作为后台的入口文件,于是域名/admin.php就可以访问后台了(默认是admin模块的index控制器的index方法),虽然可以访问了,但是我是个完美主义者,或者说室友强迫症的人,我觉得admin.php的.php看上去很是刺眼,要是能去掉就更好了,于是我就想到了把nginx的配置改一下,抱着试一试的态度,结果还是挺满意的,去掉了尾巴看上去爽多了,下面贴上代码

入口文件admin.php

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21
<?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

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20
<?php

/*

*功能:后台首页控制器

*作者:魏安来

*日期:2017/12/12

*/

namespace app\\admin\\controller;

class Index extends Base{

/*后台首页*/

public function index(){

return 'admin';

//return $this->fetch();

}

}

?>

nginx配置vhosts.conf

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26
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多入口设置内容请搜索快网idc以前的文章或继续浏览下面的相关文章希望大家以后多多支持快网idc!

原文链接:https://www.cnblogs.com/walblog/p/8035426.html

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 TP5多入口设置实例讲解 https://www.kuaiidc.com/91268.html

相关文章

发表评论
暂无评论