我可以';t从CodeIgniter URL中删除index.php


I can't remove the index.php from the CodeIgniter URL

我想从CodeIgniter中的路径中删除index.php。

我试图将配置文件中index_page的值更改如下:

$config['index_page'] = '';

然后我尝试了所有这些。htaccess:

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|'.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

Options -Indexes
RewriteEngine on
RewriteCond $1 !^(index'.php|assets/|robots'.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteEngine on
RewriteCond $1 !^(index'.php|robots'.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]  
<Files "index.php">
AcceptPathInfo On
</Files>  

但它们都没有奏效。

我还试图将uri_procol更改为:

   $config['uri_protocol']  = 'ORIG_PATH_INFO';

但它仍然不起作用。

我该如何解决这个问题?

编辑:

我尝试使用此代码来检查mod_rewrite是否已启用:

<?php
 if( ! function_exists('apache_get_modules') ){ phpinfo(); die; }
 $result = ' not available';
 if(in_array('mod_rewrite',apache_get_modules())) $result = 'available';
?>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $result"; ?></p>

我得到的结果是:

Apache/2.2.22(Ubuntu)

mod_rewrite不可用

我遇到了同样的问题。。最后,它使用了以下代码

只需遵循以下简单步骤:

1.将以下代码保存到.htaccss文件中
2.将其放入主项目文件夹(而不是应用程序文件夹)
3.将代码第3行的"/projectFolderName/"部分重命名为您的项目文件夹名称

那你就完了。刷新并查看

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

这对我有效。在.htaccess文件中写入:

RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]   

在config.php文件中:

$config['uri_protocol'] = 'AUTO';  

请确保您的htaccess位于根文件夹中,而不是应用程序文件夹中。