導航:首頁 > 編程語言 > 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相關的資料

熱點內容
linux登錄失敗次數 瀏覽:33
linuxread0 瀏覽:332
三軌直銷系統源碼 瀏覽:321
手機銀行app怎麼更新呢 瀏覽:247
單片機匯編學習 瀏覽:531
配1u伺服器主機需要注意什麼 瀏覽:38
演算法工程師小李 瀏覽:633
程序員搬到哪裡買房好 瀏覽:627
steam測試亞洲伺服器怎麼切換 瀏覽:513
vc命令行編譯工程 瀏覽:331
當貝市場解壓步驟 瀏覽:458
哪裡有賣安卓系統的app 瀏覽:472
河南省雲伺服器租賃雲主機 瀏覽:755
基金app哪個好2021年 瀏覽:41
迷你電梯單片機 瀏覽:38
編譯電腦 瀏覽:502
程序員進入網吧 瀏覽:247
cad圖轉換pdf 瀏覽:809
魔域單機版命令 瀏覽:488
ftp伺服器需要開放什麼埠 瀏覽:327