简体   繁体   中英

Codeigniter function controller 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');      
    }

}

When i try to access localhost/site/go/contest I get a 404. The default controller is "Go". Some of my config values:

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

My .htaccess file:

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

Whats the problem ???

Try with this code

in your .htaccess add you folder name

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

In config.php:

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

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

Use this configuration

In config

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

.htaccess:

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

You want to change your base_url to point to the root of your CI installation (in your case, localhost/sajt/ . This setting is used to construct links when using the site_url() function, it should not be used to define a default controller. The default controller should be defined in config/routes.php as follows:

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

The index() method is automatically entered if no method is specified, provided that it exists.

You also want to rewrite relative to index.php in your .htaccess file, but you have an absolute path of / specified. This is a problem if you have CI installed in a subdirectory. I'd suggest the following:

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

There, I test to see if the requested URI is in fact not a file or directory, which eliminates having to specify them one by one, and the RewriteBase directive makes sure that the links are rewritten properly.

try

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

and add

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

to your .htaccess file

please look at the documentation

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

1º click menu wamp>apache>httpd.conf CHANGE :

#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º application/conf/ config.php

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

URL case sensitive

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

5º Test

localhost/site/index.php/controller

if it works, go to : http://ellislab.com/codeigniter/user-guide/general/urls.html

try in 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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM