ThinkPHP 去掉 public 和 index.php

去掉 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 ALL
	Options None
	Order allow,deny
	Allow from all
</Directory>

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

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

<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

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

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

猜你喜欢

转载自blog.csdn.net/SGamble/article/details/82811503