codeigniter路由不工作 [英] codeigniter routes is not working

查看:111
本文介绍了codeigniter路由不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有CodeIgniter的以下问题。我尝试设置菜单,并使用路由配置加载正确的内容,但从某种原因,它不工作。

I have the following problem with CodeIgniter. I'm trying to setup a menu, and using route config to load the proper content but from some reason it's not working.

我有CodeIgniter设置下:

I have CodeIgniter setup under:

http://localhost/new/CodeIgniter/

我的配置文件看起来像这样:

My config file looks like this:

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

我的路由配置如下所示:

My route config looks like this:

$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;

这是我的Home控制器:

And this is my Home controler:

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 / 我可以看到主页,但以下都没有工作:

When I access http://localhost/new/CodeIgniter/ I can see the home page, but none of the following are working:

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

有人知道我在这里做错了吗?

Does anyone has any idea what I'm doing wrong here?

错误如下:

Not Found

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

这是我的httaccess

This is my 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>


推荐答案

确保您已启用mod_rewrite =http://stackoverflow.com/questions/21957731/codeigniter-where-to-put-htaccess> phpinfo 启用或不启用)。

Make sure you mod_rewrite enabled (check through phpinfo that is enable or not).

以下


  1. Linux

  2. 对于视窗

  1. For Linux
  2. For window

并添加此.htacess

And add this .htacess

添加

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

在您的根文件夹

这篇关于codeigniter路由不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆