我是新来的笨框架,我试图让我的第一个程序,但收到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";
我曾尝试以下URL http://localhost/Codeigniter/
但我得到一个404错误,但是http://localhost/Codeigniter/home
加载,即使我的实际根文件夹是笨正确的结果
如何解决这个问题呢?
更改路由文件在此路径如下: -
CodeIgniter/application/config/routes.php
$route['default_controller'] = 'required_controller';
那么只有你可以访问以下网址
http://localhost/Codeigniter/
尝试在那里
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 这里
确保您的htaccess是应用程序文件夹之外。
然后在config.php文件
$config['base_url'] = 'http://localhost/codeigniter/';
$config['index_page'] = '';
然后你就可以在routes.php文件最好设置你的routes.php文件小写
$route['default_controller'] = 'home';