<?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]
问题是什么?
答案 0 :(得分:1)
尝试使用此代码
在.htaccess中添加文件夹名称
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /site/index.php/$1 [L]
答案 1 :(得分: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]
答案 2 :(得分:0)
使用此配置
在配置
中$config['base_url'] = '';
$config['index_page'] = '';
htaccess的:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /site/index.php/$1 [L]
答案 3 :(得分:0)
您希望将base_url
更改为指向CI安装的根目录(在您的情况下为localhost/sajt/
。此设置用于在使用site_url()
功能时构建链接,它不应该用于定义默认控制器。默认控制器应该在config/routes.php
中定义如下:
$route['default_controller'] = "go";
如果没有指定方法,则会自动输入index()
方法,前提是它存在。
您还想在.htaccess文件中将 relative 重写为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
指令确保链接被正确重写。
答案 4 :(得分: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
答案 5 :(得分:0)
1° 点击菜单wamp&gt; apache&gt; 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º网址区分大小写
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]