我想从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_protocol更改为:
$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不可用
答案 0 :(得分:3)
我有同样的问题..然后最终它使用以下代码
只需按照以下简单步骤操作:
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>
答案 1 :(得分:0)
这对我有用。在.htaccess文件中写:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
并在你的config.php文件中:
$config['uri_protocol'] = 'AUTO';
确保你的根文件夹中的htaccess不在应用程序文件夹中。