溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

tp5.0框架如何隱藏index.php入口文件及模塊和控制器

發(fā)布時(shí)間:2021-08-18 10:58:03 來源:億速云 閱讀:154 作者:小新 欄目:開發(fā)技術(shù)

這篇文章將為大家詳細(xì)講解有關(guān)tp5.0框架如何隱藏index.php入口文件及模塊和控制器,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

1. 隱藏入口文件:

[ IIS ]

在IIS的高版本下面可以配置web.Config,在中間添加rewrite節(jié)點(diǎn):

<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

把下面的內(nèi)容保存為.htaccess文件放到應(yīng)用入口文件的同級(jí)目錄下

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]//此處與官網(wǎng)不同,官網(wǎng)是這樣寫,嘗試不中,修改成一下可以
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

2. 模塊和控制器隱藏:

public目錄下的index.php入口文件里添加define('BIND_MODULE', 'index/index');,如下:

<?php
// [ 應(yīng)用入口文件 ]
define('BIND_MODULE', 'index/index');
// 定義應(yīng)用目錄
define('APP_PATH', __DIR__ . '/../application/');
// 加載框架引導(dǎo)文件
require __DIR__ . '/../thinkphp/start.php';

設(shè)置后,我們的URL訪問地址則變成:

http://serverName/index.php/操作/[參數(shù)名/參數(shù)值...]

擴(kuò)展:

tp5.1隱藏控制器和模塊與5.0不同,入口文件中修改如下:

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

關(guān)于“tp5.0框架如何隱藏index.php入口文件及模塊和控制器”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI