2015-07-13 162 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