jaread83
jaread83

Reputation: 49

Amazon EC2 .htaccess 500 internal error

I have an Amazon EC2 instance with a simple PHP website. It works perfectly fine on my local PHP server but when viewing on the AWS I get a 500 Internal Server Error. I think there is something wrong with my htaccess file but I cant figure it out.

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]

When I comment out the last 2 lines I don't get the error but I still need this to access my php code.

Thank you in advance for your time.

Upvotes: 0

Views: 6511

Answers (2)

vinod
vinod

Reputation: 2880

I noticed few common issues

  1. Make sure mod_rewrite enabled in apache configuration.
#On ubuntu os you can try it like this 
sudo a2enmod rewrite
sudo service apache2 restart
  1. Check the website's main Apache configuration file. For the main domain on a server, this will typically be:

Ubuntu and 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. If still you are facing same issue then delete your .htaccess file and create it again from command becuase some time character encoding issue of file lead to such type of issues. For example in your apache log you may see such type of error

/.htaccess: Invalid command '\xef\xbb\xbf##', perhaps misspelled or defined by a module not included in the server configuration

To resolve this type of character encoding issue go to your root directory after deleting .htaccess file and create this file again as :

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

Now put your .htaccess file code in opend file.

Upvotes: 1

anubhava
anubhava

Reputation: 784928

Try these rules:

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]

Upvotes: 0

Related Questions