codeigniter路由不起作用

时间:2015-07-31 08:54:43

标签: php codeigniter routes

CodeIgniter存在以下问题。我尝试设置菜单,并使用路由配置加载正确的内容但由于某种原因它无法正常工作。

我在CodeIgniter下设置:

http://localhost/new/CodeIgniter/

我的配置文件如下所示:

$config['base_url'] = 'http://localhost/new/CodeIgniter/';
$config['index_page'] = '';

我的路线配置如下:

$route['default_controller'] = 'Home/home';
$route['404_override'] = '';
$route['home'] = 'Home/home';
$route['compare'] = 'Home/home';
$route['signin'] = 'Home/home';
$route['translate_uri_dashes'] = FALSE;

这是我的家庭控制器:

class Home extends CI_Controller {

public function __construct()
{
    parent::__construct(); 
} 

public function index() 
{
    $this->home();
}

public function home()
{
    $this->load->model('home_model');

    $this->load->view('header_view', $data);
    $this->load->view('nav_view', $data);
    $this->load->view('home_view', $data);
    $this->load->view('footer_view', $data);
}

public function compare()
{
    $this->load->model('home_model');

    $this->load->view('header_view', $data);
    $this->load->view('nav_view', $data);
    $this->load->view('home_view', $data);
    $this->load->view('footer_view', $data);
}

public function signin()
{
    $this->load->model('home_model');

    $this->load->view('header_view', $data);
    $this->load->view('nav_view', $data);
    $this->load->view('home_view', $data);
    $this->load->view('footer_view', $data);
}   

public function about()
{
    $this->load->model('home_model');

    $this->load->view('header_view', $data);
    $this->load->view('nav_view', $data);
    $this->load->view('home_view', $data);
    $this->load->view('footer_view', $data);
}   
}

当我访问http://localhost/new/CodeIgniter/时,我可以看到主页,但以下任何一项都无效:

http://localhost/new/CodeIgniter/home
http://localhost/new/CodeIgniter/compare
http://localhost/new/CodeIgniter/signin
http://localhost/new/CodeIgniter/about

有没有人知道我在这里做错了什么?

错误如下:

Not Found

The requested URL /new/CodeIgniter/home was not found on this server.

这是我的httaccess

<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>
<IfModule ModRewite>
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

2 个答案:

答案 0 :(得分:0)

我认为缺少.htaccess文件。使用此内容创建一个新文件并将其保存在CI根目录中。

RewriteEngine on
RewriteBase /new/CodeIgniter
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

答案 1 :(得分:0)

确保启用了mod_rewrite(通过all the functions you need检查是否启用)。

启用mod_rewrite检查

  1. 适用于phpinfo
  2. 适用于Linux
  3. 并添加此.htacess

    window

    RewriteEngine on
    RewriteCond $1 !^(index.php|resources|robots.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    

    在根文件夹中