ThinkPHP重写路由,掩藏public/index.php

  在thinkPHP项目中,为了掩藏 public/index.php 路径时,需要修改相关的 Apache httpd.confi 文件、ThinkPHP .htaccess文件

修改 Apache httpd.confi 增加 mod_rewrite.so 来重写路由

  打开 httpd.confi 文件:修改三个地方

LoadModule rewrite_module modules/mod_rewrite.so  //启用 mod_rewrite.so

<Directory "${SRVROOT}/cgi-bin">
    AllowOverride All
    Options None
    Require all granted
</Directory>

AllowOverride All

修改 ThinkPHP .htaccess 文件:这里需要说明一下,我的 index.php、.htaccess文件都是放在根目录上,因此相关修改需要根据 初始模块位置而定。

  

  .htaccess 中文件的配置:

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

  index.php 文件配置:

<?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/');
// 加载框架引导文件
require __DIR__ . '/thinkphp/start.php';

  效果:

原文地址:https://www.cnblogs.com/mysouler/p/9524808.html