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

base_urlCI インストールのルートを指すように変更したい(あなたの場合は、 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 が実際にファイルやディレクトリではないかどうかをテストします。これにより、それらを 1 つずつ指定する必要がなくなり、RewriteBaseディレクティブによってリンクが適切に書き換えられることが確認されます。

于 2012-12-19T10:34:11.797 に答える
0

この構成を使用する

構成内

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

.htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /site/index.php/$1 [L]
于 2012-12-19T10:32:01.130 に答える
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]
于 2012-12-19T10:30:04.963 に答える
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 に答える