我是codeigniter框架的新手,我试图制作我的第一个程序,但收到了404 page not found
错误
这是我的根目录Codeigniter
和我的目录结构
我的源文件夹包含包含以下代码的.htaccess文件
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Home.php
class Home extends CI_Controller{
public function index(){
$this->load->view('View');
}
}
view.php
echo "HI this is my first codeigniter program";
我尝试过以下网址http://localhost/Codeigniter/
但是我
得到404错误,但http://localhost/Codeigniter/home
加载正确的结果,即使我的实际根文件夹是Codeigniter
如何解决这个问题?
答案 0 :(得分:3)
Change route file in this following path:-
CodeIgniter/application/config/routes.php
$route['default_controller'] = 'required_controller';
Then only you can access the following url
http://localhost/Codeigniter/
答案 1 :(得分:2)
试试
RewriteRule .* index.php/$0 [PT,L]
更改为
RewriteRule .* index.php/$1 [PT,L]
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
或者
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
更多htaccess here
确保您的htaccess位于应用程序文件夹之外。
然后在config.php
$config['base_url'] = 'http://localhost/codeigniter/';
$config['index_page'] = '';
然后你可以在routes.php
上设置你的routes.php小写$route['default_controller'] = 'home';