2012-11-10 232 views
3

是的,另一個這樣的。我嘗試了所有可以在搜索中找到的東西,但沒有運氣。刪除codeigniter的index.php

在我的httpd.conf(運行CentOS的和apache2的):

<VirtualHost *:80> 
ServerName www.domain.com 
ServerAlias domain.com *.domain.com 
DocumentRoot /var/www/html/domain.com 
</VirtualHost> 

在我的htaccess在/var/www/html/domain.com:

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

一切似乎是工作。

我已經嘗試添加

RewriteBase/

我試過的最後一行切換到:

RewriteRule ^(.*)$ /index.php/$1 [L] 
+0

什麼是你想在這裏實現? – praseodym

+0

@praseodym他試圖將index.php移出CodeIgniter網址。 – Kenzo

+0

正確。我試圖從http://domain.com/index.php/features 轉到http://domain.com/features –

回答

4

你需要確保你的虛擬主機,你必須:

<Directory "/path...to directory"> 
     Order allow,deny 
     Allow from all 
     Allowoverride all 
    </Directory> 

    <IfModule mod_rewrite.c> 
     RewriteEngine on 
    </IfModule> 
+1

固定。這確實需要在CI文檔中。我已經看到了它,但不會認爲這會影響它... –

+0

@Sheldon Kennedy它曾經在Github上的Wiki文檔中。但有人把它拿出來了。 沒有「Allowoverride all」部分,Apache根本不會讀取您的.htaccess文件。對需要.htaccess文件的其他應用程序很有用。 – Kenzo

+0

謝謝。我不知道這一點。我認爲httpd.conf中的一個指令(AccessFileName)允許.htaccess –

0

原始帖子(以及CI用戶指南)中的規則可用於允許URL在沒有的情況下工作,但不會從現有網址中刪除/index.php/

您可以在CI配置中設置$config['index_page'] = '';(刪除index.php),以從CI生成的URL中刪除index.php

如果原來的規則不工作,請給這些重寫規則一試:

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

他仍然需要改變他的httpd.conf – Kenzo

+0

我不明白爲什麼虛擬主機設置很重要。如果'RewriteEngine on'失敗或'.htaccess'中的某些行不被允許,Apache將響應服務器錯誤。 – praseodym

+0

因爲他需要「Allowoverride all」部分,否則Apache甚至不會讀取.htaccess文件。 – Kenzo

0

兩個諮詢點:

1)一定要保存/編輯.htaccess文件到您的項目文件夾的根目錄,而不是/ applications文件夾中的.htaccess。這樣,如果我的應用程序文件夾位於項目/應用程序中,請不要編輯project/application/.htaccess文件。你需要你的文件位於項目/的.htaccess

2)使用.htaccess文件如下:

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