简体   繁体   English

我无法从CodeIgniter URL中删除index.php

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

I want to remove index.php from the path in CodeIgniter. 我想从CodeIgniter中的路径中删除index.php。

I tried to change the value of index_page in the config file as the following: 我试图在配置文件中更改index_page的值,如下所示:

$config['index_page'] = '';

then I tried all these .htaccess : 然后我尝试了所有这些.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>  

But none of them has worked. 但它们都没有奏效。

I also tried to to change the uri_protocol to this : 我还试图将uri_protocol更改为:

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

But it's still doesn't work. 但它仍然无效。

How can I solve this problem ? 我怎么解决这个问题 ?

Edit : 编辑:

I tried this code to check if the mod_rewrite is enabled : 我尝试使用此代码来检查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>

And I get this result : 我得到了这个结果:

Apache/2.2.22 (Ubuntu) Apache / 2.2.22(Ubuntu)

mod_rewrite not available mod_rewrite不可用

I had the same issue.. then finally it worked with the following code 我有同样的问题..然后最终它使用以下代码

just follow these simple steps : 只需按照以下简单步骤:

1. save the following code into .htaccss file.. 1.将以下代码保存到.htaccss文件中..
2. put it in the main project folder (not the application folder) 2.把它放在主项目文件夹(不是应用程序文件夹)中
3. rename the "/projectFolderName/" part on 3rd line of the code as your project folder name. 3.将代码第3行的“/ projectFolderName /”部分重命名为项目文件夹名称。

Then you are done. 然后你就完成了。 Refresh and see. 刷新并看到。

<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>

This works for me. 这适合我。 Inyour .htaccess file write: Inyour .htaccess文件写道:

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

and in your config.php file : 并在您的config.php文件中:

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

Make sure yout htaccess is in your root folder not in applications folder. 确保你的根文件夹中的htaccess不在应用程序文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM