无法在 Codeigniter 中删除 index.php

Unable to remove index.php in Codeigniter

我想删除 index.php 以直接访问我的控制器。但是,我不能直接去我的控制器。我必须使用 index.php。例如:我想去 http://example.com/my_controller/method instead of http://example.com/index.php/my_controller/method

顺便说一句,我使用了我的测试服务器,而不是像 XAMPP 这样的本地服务器。我在我的服务器中启用了 apache mod 重写。

我尝试了很多 htaccess 规则和条件,但我无法使用。请帮助我!

这是我的 .htaccess 文件:

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

我的config.php:

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

怎样才能直接去?

如何验证 mod_rewrite 是否实际启用。您可以按照此处的说明进行操作:How to check whether mod_rewrite is enable on server?

在您的 .htaccess 文件中尝试此代码

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