如果没有index.php,我无法访问base_url/controller/方法,我尝试使用.htaccess删除index.php,但仍然无法工作。404找不到页面但我的另一个项目在同一个示例中使用相同的设置
这是我的config.php
$config['base_url'] = 'http://localhost/sistem-informasi-bimbel/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
这是我的routes.php
$route['default_controller'] = 'main/home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = TRUE;
这是我的.htaccess文件,我把它放在应用程序文件夹之外
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
在httpd.conf 上启用mod重写
LoadModule rewrite_module modules/mod_rewrite.so
这段代码非常适合我。
您需要在主控制器下创建一个gallery()
。如下所示:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Main extends CI_Controller {
public function gallery()
{
$this->load->view('welcome_message');
}
}