假设您使用 Apache 作为启用了 ModRewrite 的 Web 服务器,您需要在 CodeIgniter 中正确设置此设置:
1. 正确编写.htaccess
2. 有效application/config/config.php
文件
3. 有效index.php
文件。
让我们一一讨论。
.htaccess
配置
在您的示例中,您缺少RewriteBase
声明。您需要将该声明与您的可公开访问目录的绝对路径一起添加。这是.htaccess
公共目录基础中的文件。
RewriteEngine on
RewriteBase /absolute/path/to/blue(public_html)/
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
config.php
配置
在application/config/config.php
你需要确保你已经正确设置了你的base_url
和index_page
选项。要从index.php
URL 中删除,您必须将该index_page
选项设置为空白。
/*
|---------------------------------------------------------------
| Base Site URL
|---------------------------------------------------------------
*/
$config['base_url'] = 'localhost/blue';
/*
|---------------------------------------------------------------
| Index File
|---------------------------------------------------------------
*/
$config['index_page'] = ''; // <-- note that this is empty!
index.php
配置
您的index.php
配置文件位于可公开访问的目录的根目录中。在这里,您需要设置应用程序和系统文件夹的绝对路径。
/*
*---------------------------------------------------------------
* SYSTEM FOLDER NAME
*---------------------------------------------------------------
...
*/
$system_path = '/absolute/path/to/code_igniter/system';
/*
*---------------------------------------------------------------
* APPLICATION FOLDER NAME
*---------------------------------------------------------------
...
*/
$application_folder = '/absolute/path/to/code_igniter/application';
一旦你在 CI 中修复了这三件事,你应该能够在没有URL 的情况下点击localhost/blue 。index.php