2015-07-13 165 views
0

我有一個簡單的PHP網站的亞馬遜EC2實例。它在我的本地PHP服務器上工作得很好,但在AWS上查看時,我得到一個500內部服務器錯誤。我認爲我的htaccess文件有問題,但我無法弄清楚。亞馬遜EC2 .htaccess 500內部錯誤

Options -Indexes 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} /([^/]+)/?$ [NC] 
RewriteRule (.*)\.html application/index.php?key=$1 [L] 
RewriteRule ^$ application/index.php?key=index [L] 
RewriteRule ^([^\.]+)$ $1.html [NC,L] 

當我註釋掉最後兩行我不明白的錯誤,但我仍然需要用它來訪問我的PHP代碼。

預先感謝您的時間。

+0

是您的htaccess的簽入混帳?我有一個彈性豆莖類似的問題,這意味着Htaccess沒有被上傳 – terrorfall

+0

我沒有在這個實例上使用git。現在只需使用FTP將我的文件上傳到服務器即可。我嘗試使用vim在終端窗口中重新創建上述.htaccess。 – jaread83

+0

你的規則看起來不正確。您正在將'.html' URI重寫爲'application/index.php',然後再次添加'.html'。 – anubhava

回答

0

嘗試下列規則:

Options -Indexes 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/.]+)\.html$ application/index.php?key=$1 [L,QSA] 

RewriteRule ^$ application/index.php?key=index [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^([^.]+?)/?$ $1.html [L] 
+0

這在我的本地MAMP服務器上按預期工作,但仍在AWS服務器上產生500錯誤。我通過終端(sudo nano /etc/httpd/conf/httpd.conf)編輯了httpd.conf文件以允許在根文件夾模塊中覆蓋所有內容,但仍然沒有運氣 – jaread83

+0

您需要檢查服務器上的Apache error.log以查看錯誤你得到500.不知道實際的錯誤,很難猜測爲什麼它在一個Apache上工作,但不能在其他Apache上工作。 – anubhava

+1

我會看看。如果我找到解決方案,我會回到這裏。非常感謝你的時間與我一起看看這個。 – jaread83