Codeigniter功能控制器404

时间:2012-12-19 10:23:13

标签: php codeigniter

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Go extends CI_Controller {

    public function index()
    {
        //$this->load->view('welcome_message');
        $this->load->helper('url');

        $this->load->view('start_view');
        $this->load->view('header_view');
        $this->load->view('menu_view');
        $this->load->view('top_panel_view');
        $this->load->view('domaci_view');
        $this->load->view('world_view');
        $this->load->view('latest_view');
        $this->load->view('end_view');
    }

    public function contest()
    {
        $this->load->helper('url');

        $this->load->view('start_view');
        $this->load->view('header_view');
        $this->load->view('menu_view');
        $this->load->view('end_view');      
    }

}

当我尝试访问localhost / site / go / contest时,我得到404.默认控制器是“Go”。我的一些配置值:

$config['index_page'] = ''; 
$config['base_url'] = 'http://localhost/sajt/go';

我的.htaccess文件:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

问题是什么?

6 个答案:

答案 0 :(得分:1)

尝试使用此代码

在.htaccess中添加文件夹名称

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /site/index.php/$1 [L]

答案 1 :(得分:0)

在config.php中:

$config['base_url'] = '';
$config['index_page'] = '';

在routes.php中:

$route['default_controller'] = 'go/index';

htaccess的:

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]

答案 2 :(得分:0)

使用此配置

在配置

$config['base_url'] = '';
$config['index_page'] = '';

htaccess的:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /site/index.php/$1 [L]

答案 3 :(得分:0)

您希望将base_url更改为指向CI安装的根目录(在您的情况下为localhost/sajt/。此设置用于在使用site_url()功能时构建链接,它不应该用于定义默认控制器。默认控制器应该在config/routes.php中定义如下:

$route['default_controller'] = "go";

如果没有指定方法,则会自动输入index()方法,前提是它存在。

您还想在.htaccess文件中将 relative 重写为index.php,但是您指定了/的绝对路径。如果在子目录中安装了CI,则会出现此问题。我建议如下:

<IfModule mod_rewrite.c>
        Options +FollowSymLinks
        RewriteEngine on
        RewriteBase /sajt
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>

在那里,我测试看看请求的URI实际上是否一个文件或目录,这样就不必逐个指定它们,RewriteBase指令确保链接被正确重写。

答案 4 :(得分:0)

尝试

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

并添加

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

到您的.htaccess文件

请查看文档

http://ellislab.com/codeigniter/user-guide/general/urls.html

答案 5 :(得分:0)

1° 点击菜单wamp&gt; apache&gt; httpd.conf 更改

#LoadModule rewrite_module modules/mod_rewrite.so

LoadModule rewrite_module modules/mod_rewrite.so

.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

3ºapplication/ conf / config.php

$config['base_url'] = '';
$config['index_page'] = '';

网址区分大小写

localhost/SITE/controller = c:\SITE\controller
localhost/site/controller = c:\site\controller

5º测试

localhost/site/index.php/controller

如果有效,转到http://ellislab.com/codeigniter/user-guide/general/urls.html

尝试 config.php

$config['uri_protocol'] = “REQUEST_URI”

Alternartive .htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|css|js|img|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]