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

熱點內容
高中畢業當程序員 瀏覽:245
php標簽屬性大全 瀏覽:897
遠程訪問伺服器ip地址 瀏覽:312
程序員吃雞蛋炒菜 瀏覽:173
在哪裡看俄羅斯電視劇app 瀏覽:308
怎麼找資料庫伺服器地址 瀏覽:487
伺服器調試怎麼翻譯 瀏覽:921
php如何處理ajax請求 瀏覽:211
php數組下標存在 瀏覽:707
php獲取ip歸屬地 瀏覽:175
撩女程序員怎麼辦 瀏覽:508
百度伺服器做什麼 瀏覽:193
打開軟體加速伺服器有什麼危害 瀏覽:87
php去除數組下標 瀏覽:794
ipad的app內容哪裡看 瀏覽:284
遇見空間app在哪裡 瀏覽:547
用命令對一個文件內容進行統計 瀏覽:317
華為交換機配置命令縮寫 瀏覽:344
鏈接伺服器出現問題怎麼處理 瀏覽:834
華為手機怎麼打開加密 瀏覽:676