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

熱點內容
字幕網app怎麼找 瀏覽:528
奧迪a4l壓縮比 瀏覽:693
iis7伺服器怎麼安裝 瀏覽:975
孩子上學壓力太大怎麼解壓 瀏覽:236
javaurl格式 瀏覽:342
勻稱app怎麼用 瀏覽:61
pythonemail中文亂碼 瀏覽:442
android訪問html 瀏覽:88
做一個app或者網頁用什麼編程 瀏覽:776
一體機伺服器運行失敗怎麼辦 瀏覽:936
longjava比較大小 瀏覽:531
clojure編程pdf 瀏覽:22
一年級數學圈一圈的演算法 瀏覽:111
完整的python 瀏覽:42
c51單片機數字鍾 瀏覽:923
apk文件反編譯後安裝包損壞 瀏覽:816
app圖標分別是什麼 瀏覽:368
linux全選命令 瀏覽:365
怎麼用華碩app 瀏覽:963
小明台灣通道加密 瀏覽:376