无法使用Codeigniter URL删除WAMP中的index.php

Jer*_*lle 5 php .htaccess codeigniter

我想删除URL中的index.php,但它不起作用.这是我做的:

  1. 我在Apache中启用rewrite_module然后重启服务器
  2. 我编辑了codeigniter文件夹中的.htaccess.我根据文档中的示例添加了这个.

    RewriteEngine On

    RewriteCond%{REQUEST_FILENAME}! - f

    RewriteCond%{REQUEST_FILENAME}!-d

    RewriteRule ^(.*)$ index.php/$ 1 [L]

  3. 然后我也删除了app/config中的index.php

  4. 然后我创建一个简单的控制器:

    class Users extends CI_Controller {
    
        public function __construct() {
            parent::__construct();
        }
    
        public function index() {
            echo "hello world";
        }
    
    }
    
    Run Code Online (Sandbox Code Playgroud)

当我访问此网址时:

http://localhost/order_menu/users
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误:

Not Found

The requested URL /order_menu/users was not found on this server.
Run Code Online (Sandbox Code Playgroud)

你能帮帮我吗?

Mr.*_* ED 6

删除wamp apache服务器上的codeigniter中的index.php!

使用wamp时确保已启用Apache Modules"rewrite_module"重启服务器

第二

在项目的主目录中尝试这个htaccess

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)

然后转到application/config/config.php

$config['index_page'] = 'index.php';

然后使index.php为空

用...来代替 $config['index_page'] = '';

您可能需要配置路由

CI3:http://www.codeigniter.com/user_guide/general/routing.html

CI2:http://www.codeigniter.com/userguide2/general/routing.html