CodeIgniter功能控制器404


<?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/竞赛时,我将获得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]

问题是什么???

尝试使用此代码

在您的.htaccess中添加您的文件夹名称

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

在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]

使用此配置

在config

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

.htaccess:

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

您想更改base_url以指向CI安装的根(在您的情况下,localhost/sajt/。使用site_url()函数时,此设置用于构造链接,不应是用于定义默认控制器。默认控制器应在config/routes.php中定义如下:

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

如果未指定方法,则自动输入index()方法,只要它存在。

您还需要将.htaccess文件中的相对重写为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>

在那里,我测试是否实际上是不是文件或目录,这消除了必须一一指定它们,并且RewriteBase指令确保链接已重写正确。

尝试

$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

1º单击菜单wamp> apache> httpd.conf 更改

#LoadModule rewrite_module modules/mod_rewrite.so

to

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º应用程序/conf/ config.php

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

URL案例敏感

localhost/SITE/controller = c:SITEcontroller
localhost/site/controller = c:sitecontroller

5º测试

localhost/site/index.php/controller

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

尝试 config.php

$config['uri_protocol'] = “REQUEST_URI”

替代品.htaccess

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

最新更新