2011-07-20 77 views
6

我试图从我的CI网址中删除index.php,但按照说明它似乎没有工作。使用htaccess删除子目录中的codeigniter index.php

我有一个codeigniter安装在子目录中运行。在route config中有一个默认控制器,名为main,另一个控制器叫做'create'。默认运行正常,但去/创建返回一个324错误,说没有收到数据。我的htaccess看起来像这样:

<IfModule mod_rewrite.c> 

RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 

</IfModule> 

<IfModule !mod_rewrite.c> 
    ErrorDocument 404 /index.php 
</IfModule> 
+0

你的apache error.log的输出将有助于解决你的问题。 – Marko

回答

24

这应该是足够了:

<IfModule mod_rewrite.c> 
RewriteEngine On 

#Checks to see if the user is attempting to access a valid file, 
#such as an image or css document, if this isn't true it sends the 
#request to index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
#This last condition enables access to the images and css folders, and the robots.txt file 
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css) 
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 
+1

这个效果很好。谢谢! – Robin

+0

赢家是...这个。 – dlopezgonzalez

+0

并不要忘记更改apache配置提到stackoverflow.com/a/14807463/1537413 – Dika

7

这就是我使用的。我的CodeIgniter也运行在一个子目录中。

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt) 
RewriteRule ^(.*)$ /ci/index.php/$1 [L] 
+4

我一直在寻找合适的mod_rewrite几个小时,这是最终为我工作的那个!我所要做的就是将'ci /'改成'mysubfolder /' –

5

的.htaccess地址:

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

走进的application/config/config.php文件并清除索引页配置值:

// Old 

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

// New 

$config['index_page'] = ""; 

解决了我的问题希望别人也.. :)

+0

我试图codeigniter用户指南的代码,并没有工作,但现在它的工作像魔术谢谢先生 – Belajar

+0

这对我来说,谢谢! – Robin

1

有时你需要启用它重写模块,运行“的Apache2能模块重写”:

sudo a2enmod rewrite 

您需要重新启动Web服务器以应用更改:

sudo service apache2 restart 

然后按照索非亚的回答。