2012-12-19 115 views
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');  
    } 

} 

當我嘗試訪問本地主機/網站/去/比賽時,我得到了404。默認控制器是「去」。我的一些配置值:Codeigniter功能控制器404

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

請告訴我問題???

+0

安裝在網站名爲子目錄笨? – PhearOfRayne

回答

1

使用此密碼嘗試使用此代碼

在您的。.htaccess中加入你的文件夾名稱

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /site/index.php/$1 [L] 
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] 
0

使用此配置

在配置

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

的.htaccess:

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /site/index.php/$1 [L] 
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指令品牌確保鏈接被正確地重寫。

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

+0

一些解釋會幫助這個答案 – dove

0

1º 點擊菜單WAMP>阿帕奇>的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º應用程序/ 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」 

Alternartive的.htaccess

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