tp5.0隐藏index.php入口文件以及模块和控制器

  1. 隐藏入口文件:
    [ IIS ]
    在IIS的高版本下面可以配置web.Config,在中间添加rewrite节点:
<rewrite>
 <rules>
 <rule name="OrgPage" stopProcessing="true">
 <match url="^(.*)$" />
 <conditions logicalGrouping="MatchAll">
 <add input="{HTTP_HOST}" pattern="^(.*)$" />
 <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
 <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
 </conditions>
 <action type="Rewrite" url="index.php/{R:1}" />
 </rule>
 </rules>
 </rewrite>

[ Apache ]
httpd.conf配置文件中加载了mod_rewrite.so模块
AllowOverride None 将None改为 All
把下面的内容保存为.htaccess文件放到应用入口文件的同级目录下


Options +FollowSymlinks -Multiviews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]//此处与官网不同,官网是这样写,尝试不中,修改成一下可以
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]

  1. 模块和控制器隐藏:
    public目录下的index.php入口文件里添加define('BIND_MODULE', 'index/index');,如下:

// [ 应用入口文件 ]
define('BIND_MODULE', 'index/index');
// 定义应用目录
define('APP_PATH', __DIR__ . '/../application/');

// 加载框架引导文件
require __DIR__ . '/../thinkphp/start.php';

设置后,我们的URL访问地址则变成:

http://serverName/index.php/操作/[参数名/参数值...]

扩展:
tp5.1隐藏控制器和模块与5.0不同,入口文件中修改如下:

Container::get('app')->bind('index/index')->run()->send();

你可能感兴趣的:(TP5)