這篇文章將為大家詳細講解有關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文件放到應用入口文件的同級目錄下
<IfModule mod_rewrite.c>
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]
</IfModule>2. 模塊和控制器隱藏:
public目錄下的index.php入口文件里添加define('BIND_MODULE', 'index/index');,如下:
<?php
// [ 應用入口文件 ]
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.0框架如何隱藏index.php入口文件及模塊和控制器”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。