0
<?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]

有什么问题 ???

4

6 回答 6

1

尝试使用此代码

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

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /site/index.php/$1 [L]
于 2012-12-19T10:35:55.443 回答
0

在 config.php 中:

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

在 routes.php 中:

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

.ht 访问:

#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]
于 2012-12-19T10:30:04.963 回答
0

使用此配置

在配置中

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

.ht 访问:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /site/index.php/$1 [L]
于 2012-12-19T10:32:01.130 回答
0

您想更改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>

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

于 2012-12-19T10:34:11.797 回答
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

于 2012-12-19T11:10:17.890 回答
0

1º 点击菜单 wamp>apache>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º 应用程序/conf/config.php

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

URL 区分大小写

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”

替代 .htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|css|js|img|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
于 2014-07-11T19:11:53.210 回答