ThinkPHP 去掉 public 和 index.php
2022-07-28 14:14:58
184
{{single.collect_count}}

去掉 public

将 public 里的 index.php 移动到根目录,并修改内容如下:

<?php// 定义应用目录define('APP_PATH', __DIR__ . '/application/'); //目录不一样define('SITE_URL','http://xxx.com');// 加载框架引导文件require __DIR__ . '/thinkphp/start.php';

做到这一步,我们即可隐藏 public 目录。

去掉 index.php

在 APACHE (phpstudy) 里面去配置

1.将 httpd.conf 配置文件中加载 mod_rewrite.so 模块
#LoadModule rewrite_module modules/mod_rewrite.so把前面的警号去掉
2.在 APACHE (phpstudy) 里面去配置(有多处)
将 AllowOverride None 中的 None 改为 All

<Directory "D:/server/apache/cgi-bin"> AllowOverride none改为 AllowOverride ALLOptions NoneOrder allow,denyAllow from all</Directory>

3.在根目录下创建 .htaccess 文件

RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] 这句话表示将 index.php 隐藏掉的,如果不想省略就可以将这句话去掉。(public 下也有这个文件)

<IfModule mod_rewrite.c>Options +FollowSymlinks -MultiviewsRewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]</IfModule>

补充:在 windows 下不能建立以点开头的文件,你可以先随便建立一个文件

然后在 DOS 在操作 rename xx.xx .htaccess

回帖
全部回帖({{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 ? '加载中...' : '查看更多评论'}}