导航:首页 > 编程语言 > 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做什么 浏览:352
java设计模式工厂 浏览:879
php截取邮箱 浏览:702
java程序员开发三年 浏览:305
怎么设置手机网络定位服务器地址 浏览:818
威纶通触屏反编译 浏览:993
卫星天线锅出现加密信号怎么办 浏览:318
程序员都喜欢蹲厕所 浏览:925
深受顾客喜爱的程序员雇佣平台 浏览:47
程序员的招聘 浏览:749
pdf嵌入视频 浏览:846
苹果手机怎么安卓系统运行 浏览:558
学案文件夹长什么样子 浏览:677
ps虚设在哪个文件夹 浏览:591
如何下载富豪安卓 浏览:577
听动漫音乐的app哪个好 浏览:741
为什么苹果手机用安卓系统好 浏览:774
数控车床ck6130编程 浏览:913
百度app怎么登录淘宝 浏览:757
镇江ug电脑编程培训机构 浏览:446