代码点火器控制器操作路由问题



我是Codeigniter的初学者。 在.htaccess文件中

RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

在配置文件中.php我已经进行了更改

$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
$config['base_url'] = '';

在路由中.php我已将文件更改为

$route['products/register']  = 'products/register';
$route['products'] = 'products';
$route['default_controller'] = 'products';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

产品控制器

<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed'); 
class Products extends CI_Controller {  
public function __construct(){  
parent::__construct(); 
$this->load->helper(array('form', 'url'));
$this->load->library(array('session', 'form_validation', 'email')); 
$this->load->database();           
$this->load->model("product_model");  
}       
public function index()  
{  
die("aaaaa"); exit;
}  
public function register()  
{  
die("DSds");
}
}

当我在浏览器中请求 url 时 http://localhost/codei/products/register 它显示 404 页面未找到

RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

在.htaccess中尝试上面的代码,并在配置文件中设置基本url

$config['base_url'] = 'http://localhost/codei/';

使用它肯定会为您工作。 不要做任何其他事情都是完美的。 仅替换 .htaccess 代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

注意:确保 Apache 中rewrite_mode已打开

最新更新