2011-07-13 86 views
16

我在CodeIgniter中做過一個項目。它在我的本地主機上工作正常,但在遠程服務器上發出「500內部服務器錯誤」。這是我的.htaccess文件內容:CodeIgniter PHP Apache 500內部服務器錯誤

RewriteEngine On 
RewriteBase /ezgov 
RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php/$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 
+0

與我的codeigniter同樣的錯誤。託管公司說我的代碼問題,但在本地主機上的noproblem。不能指定一個鏈接,因爲每次不同的鏈接獲得500錯誤.. –

回答

3

很可能是在error_log中解釋了原因。網站的根目錄中是否有error_log?其他地方是否有日誌文件夾?原因將在那裏詳細說明。

35

打開httpd.conf文件一般位於Apache安裝目錄中的窗口

/apache/conf/httpd.conf

/etc/httpd/httpd.conf

在基於Unix的系統。 httpd.conf是一個Apache配置文件,它存儲有關服務器的各種信息。

搜索模塊mod_rewrite.so或(mod_rewrite.c在極少數情況下)。開發mod_rewrite模塊,可以即時重寫所請求的URL。大多數時候你會在評論狀態中找到。

#LoadModule rewrite_module modules/mod_rewrite.*

#這裏字符表示,它被註釋或禁用。

LoadModule rewrite_module modules/mod_rewrite.*

刪除#和使用UNIX系統在Windows命令apache -k restartservice httpd restart重新啓動Apache HTTP服務器。您還可以使用XAMPP/Wamp UI在Windows系統中重新啓動Apache。

下一頁創建.htaccess文件在根目錄下你的笨項目位於並粘貼下面的代碼

# index file can be index.php, home.php, default.php etc. 
DirectoryIndex index.php 

# Rewrite engine 
RewriteEngine On 

# condition with escaping special chars 
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA] 

下一頁查找CodeIgniter的配置文件,通常位於它的配置目錄。

./application/config/config.php

打開文件,並進行$config['index_page']值空。看起來像這樣

/* 
    |-------------------------------------------------------------------------- 
    | Index File 
    |-------------------------------------------------------------------------- 
    | 
    | Typically this will be your index.php file, unless you've renamed it to 
    | something else. If you are using mod_rewrite to remove the page set this 
    | variable so that it is blank. 
    | 
*/ 
$config['index_page'] = ''; 

現在故事結束了。一切都應該正常工作。您可以在Apache Module mod_rewrite找到更多關於httpd.config的信息。希望這可以幫助你。謝謝!!

+1

這解決了我的問題,當我在另一個網站的子文件夾中CI。謝啦。 –

+1

你搖滾。我將項目轉移到相同的文件夾,相同的數據庫,相同的身份驗證,相同的網址,但問題仍然存在,跟着你和:) – Notepad

+1

感謝你。除了httpd.conf步驟之外的所有步驟(如同在VPS上一樣,這將很困難)並且工作正常。 – cbyte

0

我解決了這個錯誤。

我得到了不同的數據庫名,我已經改變了與以下步驟:

  1. 我已經在服務器中使用的cPanel
  2. 創建的數據庫中,我創建
  3. 我已經指定以前創建的數據庫中的用戶用戶
  4. 我改變數據庫設置使用用戶名,數據庫名等
6

發佈此,J以防萬一它有助於某人...

此問題的其他答案假設您有權訪問Apache的配置文件。但是,如果您在共享主機平臺上,並且無法訪問除您應該託管文件的目錄之外的其他目錄,則訣竅就是強制PHP拋出所有錯誤,即使Apache不能。

打開駐留在codeigniter安裝根文件夾中的「index.php」;

/*switch to development environment*/ 
define('ENVIRONMENT', 'development'); 

if (defined('ENVIRONMENT')) 
{ 
    switch (ENVIRONMENT) 
     { 
      case 'development': 
      error_reporting(E_ALL); 
      /*added line below*/ 
      ini_set('display_errors', '1'); 
      break; 
...... 

做出上述更改立即開始顯示代碼出了什麼問題,我可以修復它並啓動並運行。

修復完成後,請勿忘記將codeigniter環境設置爲「生產」。

+1

謝謝!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! – dowi

+0

試過這個,屏幕上沒有顯示錯誤。我在哪裏可以找到這些錯誤? – kiirohana

+0

檢查您的瀏覽器的控制檯,並確認它是否確實是錯誤500或只是一個空白頁。 – jahackbeth

1

嘗試了這一點:

RewriteEngine on 
RewriteCond $1 !^(index\.php|public|\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?$1 

也許你有問題,你htaccess的文件。它也幫助了我。