【发布时间】:2016-02-02 07:34:26
【问题描述】:
我有一个带有 index 函数的默认控制器,可以用
调用http://localhost/myproject/welcome
但我也想处理对基本 url 的调用
http://localhost/myproject/
我该怎么做?
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller
{
public function index()
{
$this->load->view('welcome_message');
}
}
编辑: 我已将 Welcome 控制器声明为默认控制器
$route['default_controller'] = 'welcome';
这是htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
【问题讨论】:
-
您的控制器名称在 URL 中的什么位置??
-
本地主机/项目名称
-
当你的默认控制器是
welcome。您的网址类似于http://localhost/welcome -
好的,请稍等。我在帖子中犯了一个错误
-
也添加你的
base_url
标签: php codeigniter base-url