2014-06-23 110 views
2

我正在使用Ubuntu 13與本地codeigniter站點的以下設置。CodeIgniter刪除index.php不工作

Apache/2.4.6 (Ubuntu) 
5.5.3-1ubuntu2.2 
'CI_VERSION', '2.1.2' 

而且,如果沒有index.php,網址將不再有效。他們曾經工作過,但在從Ubuntu 12.x升級到13.x並在過去一年中進行了一些apache更新之後,localhost網站不再適用。

如果我去localhost/index.php/controllername/它的作品,但如果我去本地主機/控制器名/它不。

mod_rewrite已啓用。

CodeIgniter的配置有:

$config['index_page'] = ''; 
$config['uri_protocol'] = 'AUTO'; // tried all available options here and 

沒有在.conf文件工作

對我有這樣的域:

<Directory /> 
    Options -Multiviews +FollowSymLinks 
    AllowOverride All 
</Directory> 

和這裏的.htaccess文件註釋行是那些我試着那沒用。

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
# RewriteCond $1 !^(index\.php|robots\.txt) 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
# RewriteRule .* index.php/$0 [PT,L] 
# RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
</IfModule> 

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

我GOOGLE和讀到的一切我能找到,並試圖一切我能找到其中的幾個職位在這裏對堆棧溢出,包括的那些「問題,可能已經有你的答案。」不過似乎沒有什麼工作。但正如我所說,這在過去有效,但只有在多次更新操作系統和Apache後,我才第一次注意到它停止工作。

我將遠離CodeIgniter與未來的項目,但這些項目已經存在。關於什麼可能是問題,感到困惑。

SOLUTION:

原來,這是不是一個笨問題都沒有。這是一個Apache的問題,但沒有重寫規則。 在我的apache2.conf我不得不改變/ var/www/

塊要求所有授予似乎已經做了伎倆。

的DirectoryIndex index.php文件index.html的 選項指標的FollowSymLinks 的AllowOverride所有 要求所有授予

只是良好的措施,我在這裏所做的變化,以及: 有FollowSymLinks 的AllowOverride所有 要求all granted

found on askubuntu https://askubuntu.com/questions/421233/enabling-htaccess-file-to-rewrite-path-not-working

+0

你確定'mod_rewrite'已啓用嗎?它不是默認值:'sudo a2enmod rewrite'。然後'sudo service apache2 restart'。 – JakeGould

+0

你是否設置了空白變量?在配置文件? $ config ['index_page'] ='index.php'; 應該是這樣的$ config ['index_page'] =''; –

+0

閱讀此也http://ellislab.com/forums/viewthread/155801/ –

回答

0

似乎CodeIgniter似乎沒有默認的.htaccess,所以不清楚它來自哪裏。但爲了調試的目的,我建議你做下面的事情。首先,這裏是你的.htaccess全部清理:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

現在更換您index.php與此有關。它只是轉儲通過.htaccess像這樣通過$_GET值:

echo '<pre>'; 
print_r($_GET); 
echo '</pre>'; 

現在,在您.htaccess負載有問題的網站/應用程序/項目的索引頁。輸出應該是這樣的:

Array 
(
    [/controllername/here/] => 
) 

這看起來是正確的。但是,再一次,你會比我們更清楚。

這樣做的目的是評估問題是否在Apache中將正確的$_GET值傳遞給您的CodeIgniter設置,這是一個問題。或者問題是否在您的CodeIgniter控制器邏輯本身內。

我的直覺告訴我,問題是在你的代碼庫的笨邏輯,因爲從Ubuntu 12.x升級到Ubuntu 13.x包括PHP5.3版本Ubuntu 12.xUbuntu 13.x的升級版,以5.5版本。我使用的許多代碼在PHP 5.3PHP 5.4中有效,但在PHP 5.5中有時會中斷,因爲該代碼庫中的主要更改會導致代碼中斷,因爲如果您不保留非折舊功能&等。

0

我會嘗試這樣的:

RewriteRule ^(?!index)(.*)$ index.php?/myvariable=$1 [L] 

如果你知道什麼GET變量的腳本在localhost/controllername期待的controllername,然後在規則與變量名替換myvariable

1

複製下面的代碼.htaccess在您的根文件夾

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

Options All -Indexes 

也能正常工作對我來說,笨的index.php刪除。