我刚刚开始使用CodeIgniter,而且我在文档中遇到了hello world代码。每次我在url栏中输入博客控制器的名称并按Enter键,我都会收到此错误:
404 Error Page Not Found!
的本地主机/ PHP /笨/ htaccess的
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
的 route.php
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
的的config.php
$config['base_url'] = 'http://localhost/php/CodeIgniter/';
$config['index_page'] = 'index.php';
的控制器/ blog.php的
<?php
class Blog extends CI_Controller {
public function index()
{
echo 'Hello World!';
}
}
我该如何解决?
答案 0 :(得分:0)
您必须在[route.php]对应的控制器类/方法上设置URL字符串。
$route['default_controller'] = 'blog/index';
$route['blog/(:any)'] = 'blog/show/$1'
您可以保留网址&#34; http://localhost/&#34;引用&#34; /&#34;作为home在route.php上的default_controller
$config['base_url'] = 'http://localhost';
请详细了解.htaccess和友情网址。如果您收到404错误,则可能是您的网址不合适。
场所:
http://localhost/blog/lorem-ipsum
不友好:
http://localhost/index.php/blog/lorem-ipsum
文档:https://www.codeigniter.com/userguide3/general/routing.html