-1

我知道以前有人问过,但我已经尝试了所有方法,但仍然无法正常工作。也许它与 CodeIgniter 3 的新版本有关?

我的文件结构是这样的:

blue(public_html)
    --index.php
    --.htaccess

code_igniter
   --application
   --system

.htaccess文件:

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

任何帮助,将不胜感激。

4

1 回答 1

1

假设您使用 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_urlindex_page选项。要从index.phpURL 中删除,您必须将该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

于 2015-04-21T16:52:59.773 回答