本文實(shí)例講述了tp5.0框架隱藏index.php入口文件及模塊和控制器的方法。分享給大家供大家參考,具體如下:
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)是這樣寫(xiě),嘗試不中,修改成一下可以
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訪問(wèn)地址則變成:
http://serverName/index.php/操作/[參數(shù)名/參數(shù)值...]
擴(kuò)展:
tp5.1隱藏控制器和模塊與5.0不同,入口文件中修改如下:
Container::get('app')->bind('index/index')->run()->send()
更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門(mén)教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門(mén)教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門(mén)教程》及《PHP模板技術(shù)總結(jié)》。
希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:- Thinkphp5 如何隱藏入口文件index.php(URL重寫(xiě))
- 淺談thinkphp的nginx配置,以及重寫(xiě)隱藏index.php入口文件方法
- Thinkphp通過(guò)一個(gè)入口文件如何區(qū)分移動(dòng)端和PC端
- thinkphp3.2中Lite文件替換框架入口文件或應(yīng)用入口文件的方法
- ThinkPHP中url隱藏入口文件后接收alipay傳值的方法
- ThinkPHP入口文件設(shè)置及相關(guān)注意事項(xiàng)分析
- thinkphp隱藏index.php/home并允許訪問(wèn)其他模塊的實(shí)現(xiàn)方法
- ThinkPHP框架里隱藏index.php
- Nginx配置PATHINFO隱藏thinkphp index.php
- ThinkPHP3.2.3框架實(shí)現(xiàn)的空模塊、空控制器、空操作,跳轉(zhuǎn)到錯(cuò)誤404頁(yè)面圖文詳解
- thinkphp3.2實(shí)現(xiàn)跨控制器調(diào)用其他模塊的方法
- ThinkPHP中URL路徑訪問(wèn)與模塊控制器之間的關(guān)系