2011-07-20 76 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 

然後按照索非亞的回答。