当我尝试通过www.mywebsite.com/hello创建页面时,我得到404提示。我会详细说明我所拥有的。请任何人看到明显错误的东西吗?
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.well-known) [NC]
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{REQUEST_URI} !(\.well-known) [NC]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Hello extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index(){
$this->load->view('hello');
}
}
视图
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello World</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
路线
$route['hello'] = 'hello';
config
$config['uri_protocol'] = 'REQUEST_URI';
答案 0 :(得分:1)
您的**。htaccess文件应该是这样的**
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
和 config / config.php 文件应与此类似
$config['base_url'] = $base_url;
$config['index_page'] = ''; //keep it empty.
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['enable_hooks'] = FALSE;
然后再试一次。我希望它将得到解决。