[英]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');
}
}
當我嘗試訪問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]
有什么問題 ???
嘗試使用此代碼
在您的.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['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>
在那里,我進行測試以查看所請求的URI是否實際上不是文件或目錄,從而消除了必須一個接一個地指定它們的情況,並且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
至
LoadModule rewrite_module modules/mod_rewrite.so
2º 的.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'] = '';
4º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]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.