繁体   English   中英

Amazon EC2 .htaccess 500内部错误

[英]Amazon EC2 .htaccess 500 internal error

我有一个带有简单PHP网站的Amazon EC2实例。 它在我的本地PHP服务器上运行正常,但是在AWS上查看时,出现500 Internal Server Error。 我认为htaccess文件有问题,但我无法弄清楚。

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代码。

预先感谢您的宝贵时间。

我注意到了一些常见问题

  1. 确保在Apache配置中启用了mod_rewrite。
#On ubuntu os you can try it like this 
sudo a2enmod rewrite
sudo service apache2 restart
  1. 检查网站的主要Apache配置文件。 对于服务器上的主域,通常为:

Ubuntu和Debian:/etc/apache2/apache2.conf

CentOS 7:/etc/httpd/conf/httpd.conf

<Directory "/var/www/html">    
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
  1. 如果仍然遇到相同的问题,则删除.htaccess文件并从命令中再次创建它,因为一段时间的文件字符编码问题会导致此类问题。 例如,在您的Apache日志中,您可能会看到此类错误

/.htaccess:无效的命令“ \\ xef \\ xbb \\ xbf ##”,可能是拼写错误或由服务器配置中未包含的模块定义的

要解决此类字符编码问题,请在删除.htaccess文件后转到您的根目录,然后再次按以下方式创建此文件:

nano .htaccess
# or you can use any other editor like ## vi .htaccess

现在,将您的.htaccess文件代码放入打开的文件中。

尝试以下规则:

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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM