ThinkPHP5访问去除/public/index.php

原访问链接:http://localhost/public/index.php/admin/index/index
设置后访问链接:http://localhost/admin/index/index

一、复制public目录下的index.php到根目录

ThinkPHP5访问去除/public/index.php
修改内容为:

<?php
// 定义应用目录
define('APP_PATH', __DIR__ . './application/');
// 加载框架引导文件
require __DIR__ . './thinkphp/start.php';

二、在根目录新建.htaccess文件

文件内容:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On
 
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
</IfModule>