我下面有一个控制器welcome
,重定向到controllers/auth/login.php
中另一个控制器的功能
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->library('tank_auth');
}
function index() {
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login');
} else {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$this->load->view('welcome', $data);
}
}
这里,config.php
:
$config['base_url'] = '';
$config['index_page'] = 'index.php';
效果很好。但是当我在配置文件中指定base_url为:
$config['base_url'] = 'http://localhost/cilog/';
$config['index_page'] = '';
Object not found
。为什么会这样?但是当我将index_page
指定为index.php
时,它再次工作。
我相信这是因为CodeIgniter处理它的URL的方式。我不确定为什么Codeigniter这样做,但他们包括index.php
在那里的URL。
http://localhost/cilog/index.php/auth/login
你可以重写你的.htaccess
文件来删除index.php
通过把这个放在:
RewriteEngine on
RewriteCond $1 !^(index'.php|images|robots'.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
并保持你的$config['base_url']
设置为"http://localhost/cilog/"
或
同时指定$config['base_url']
和$config['index_page']
查看此处获取更多信息:http://ellislab.com/codeigniter/user-guide/general/urls.html(删除index.php文件)