.htaccess not working in amazon ec2 ubuntu instance

user1491022 picture user1491022 · Sep 18, 2013 · Viewed 12.6k times · Source

I have a server from amazon's ec2 service running on Linux Ubuntu ( Ubuntu Server 13.04 64 bit) and I have installed apache, php, and mysql. I have added a .htaccess file in my document root (i.e /var/www/).

Here is the code in .htaccess file as follows:

RewriteEngine on 
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

If I remove .php from url like "index1" instead of "index1.php", it returns 404 browser error. It works properly in my previous server.

I have .htaccess enabled in server. I did it using command "sudo vim /etc/apache2/sites-available/default" and changed "AllowOverride None" to "AllowOverride All".

I have also checked .htaccess working by passing invalid value in htaccess file and it returns "Internal server error - 500" in browser.

Here is the link of my server information : http://54.200.58.45/mytest.php

Any help in this regard will be highly appreciated.

Answer

David picture David · Jan 26, 2014

This is wat worked for me on a fresh EC2 instance with Ubuntu 13.10:

  • a2enmod rewrite
  • vim /etc/apache2/sites-enabled/000-default.conf
  • add the following to the VirtualHost
<Directory "/var/www">
  AllowOverride All
</Directory>
  • service apache2 restart