tp5.0框架隱藏index.php入口檔案及模組和控制器的方法分析
阿新 • • 發佈:2020-02-12
本文例項講述了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()
更多關於thinkPHP相關內容感興趣的讀者可檢視本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術總結》。
希望本文所述對大家基於ThinkPHP框架的PHP程式設計有所幫助。