導航:首頁 > 編程語言 > thinkphp去indexphp

thinkphp去indexphp

發布時間:2025-01-16 10:41:24

㈠ Thinkphp實現偽靜態如何去掉目錄中的index.php

Myapp是我的項目文件名,默認的訪問地址是上面這樣的。為了使URL更加簡介友好,現在要去掉中間的index.php,方法如下:
1。確認httpd.conf配置文件中載入了mod_rewrite.so 模塊,載入的方法是去掉mod_rewrite.so前面的注釋#號
2。講httpd.conf中的Allowoverride None 將None改為All
3。打開對應的項目配置文件,我的項目配置文件是Myapp/Conf/config.php ,在這個配置文件數組中增加一行,『URL_MODEL』=>2
4。在項目的根目錄下面建立一個.htaccess文件,裡面寫入下面的內容:
<IfMole rewrite_mole>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfMole>
如果你的伺服器支持rewrite,現在就可以通過http://localhost/Myapp/Index/index/訪問Index模塊下面的index操作。

㈡ thinkphp的index.php要怎麼配置才能使開啟項目的時候直接跳轉到我想要顯示的頁面

在lib文件夾內創建自定義的action控制器,並在tpl目錄下建立一個與action名稱相同的文件夾存放對應的模板文件。確保action中的function名稱與模板文件名一致。訪問網址時,默認格式為localhost/projectname/index.php?m=actionName&a=functionName,注意大小寫敏感,如需改變訪問格式,可以在配置文件中進行自定義設置。

為了使項目啟動時直接跳轉至特定頁面,您可以在index.php文件中進行一些調整。首先,找到並打開index.php文件,通常位於項目的入口目錄下。在文件中,查找並修改以下代碼段:

原代碼:

<?php

<?php

if (file_exists(RUNTIME_PATH . 'cache/app.php')) {

$app = require RUNTIME_PATH . 'cache/app.php';

} else {

$app = require __DIR__ . '/../thinkphp.php';

$config = $app->getAppConfig();

cache('app', $app->getAppCache());

}

require $app->getThinkPath() . 'think/bootstrap.php';

define('THINK_VERSION', '6.0.6');

define('EXTEND_PATH', $config['app_path'] . 'extend/');

define('RUNTIME_PATH', $config['runtime_path']);

define('APP_PATH', $config['app_path']);

define('APP_DEBUG', $config['app_debug']);

define('APP_NAMESPACE', $config['app_namespace']);

define('MODULE_PATH', $config['mole_path']);

define('MODULE_NAME', $config['mole_name']);

define('ACTION_PATH', $config['action_path']);

define('ACTION_NAME', $config['action_name']);

define('ACTION_METHOD', $config['action_method']);

require APP_PATH . MODULE_NAME . '/controller/' . ACTION_NAME . '.php';

$controller = new ACTION_NAME();

$controller->{$ACTION_METHOD}();

?>

修改後的代碼:

<?php

<?php

if (file_exists(RUNTIME_PATH . 'cache/app.php')) {

$app = require RUNTIME_PATH . 'cache/app.php';

} else {

$app = require __DIR__ . '/../thinkphp.php';

$config = $app->getAppConfig();

cache('app', $app->getAppCache());

}

require $app->getThinkPath() . 'think/bootstrap.php';

define('THINK_VERSION', '6.0.6');

define('EXTEND_PATH', $config['app_path'] . 'extend/');

define('RUNTIME_PATH', $config['runtime_path']);

define('APP_PATH', $config['app_path']);

define('APP_DEBUG', $config['app_debug']);

define('APP_NAMESPACE', $config['app_namespace']);

define('MODULE_PATH', $config['mole_path']);

define('MODULE_NAME', $config['mole_name']);

define('ACTION_PATH', $config['action_path']);

define('ACTION_NAME', $config['action_name']);

define('ACTION_METHOD', $config['action_method']);

require APP_PATH . MODULE_NAME . '/controller/' . ACTION_NAME . '.php';

$controller = new ACTION_NAME();

$controller->index();

?>

這樣,項目啟動時將直接調用index()方法,實現跳轉至您指定的頁面。

閱讀全文

與thinkphp去indexphp相關的資料

熱點內容
解壓包密碼消失 瀏覽:135
昆侖通態觸摸屏用戶窗加密 瀏覽:564
農信app怎麼看日額 瀏覽:865
iphone備忘錄包含視頻無法加密 瀏覽:283
抖音快手紅包源碼 瀏覽:137
程序員資源分析 瀏覽:586
linux交換分區大小 瀏覽:922
mt怎麼編譯 瀏覽:337
qq郵箱打開pdf 瀏覽:461
雲帆伺服器異常 瀏覽:797
初三文件夾多少頁夠用 瀏覽:878
怎樣用紙來做解壓玩具 瀏覽:275
主sip注冊伺服器地址 瀏覽:293
華為的配置命令 瀏覽:241
cmd怎麼打開java反編譯 瀏覽:683
陰離子表面活性劑分光光度計演算法 瀏覽:928
貨車空調壓縮機價格 瀏覽:557
決策樹演算法id3實例 瀏覽:685
隨意發言網源碼 瀏覽:370
app工商銀行怎麼查看卡狀態 瀏覽:550