5

I have an instance running ubuntu in ec2. I have this .htaccess file :-

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

This file is located inside the var/www/html folder. I am aiming to achieve loading of amazon-public-dns.com/index.php as amazon-public-dns.com/index.

Now, I have tried these steps :-
1) Creating the rewrite.conf in /etc/apache2/mods-enabled and in the file putting the line LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so. (Refer this answer)
2) Running the command apache2 enable module rewrite. Also, in the file /etc/apache2/sites-available/000-default.conf and writing this in the end :-

 <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        # changed from None to FileInfo
        AllowOverride All
        Order allow,deny
        allow from all
 </Directory>

Note that this answer told to edit the default. But, since that file was not there in my case, I edited the 000-default.conf file.
I restarted apache as told. But the link amazon-public-dns.com/index gives me a 404 :( Please help me.

EDIT : I put some random junk in the htaccess file. But the index.php is not giving any 500 internal server error which means that the htaccess file is being ignored. Now in

https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles

, they say to enable htaccess edit this file - /etc/apache2/sites-available/default. BUT THERE IS NO SUCH FILE

Community
  • 1
  • 1
user4647309
  • 263
  • 1
  • 3
  • 10
  • if you are still looking for the answer, this should help you, http://webmasters.stackexchange.com/questions/61009/how-to-enable-use-of-htaccess-in-apache-on-ubuntu – Niranjan N Raju Dec 02 '15 at 10:19

3 Answers3

2

following command works for me Great !

sudo a2enmod rewrite
sudo service apache2 restart

To check loaded modules

sudo apache2ctl -M
Kamal Kumar
  • 3,393
  • 2
  • 19
  • 15
1

The default conf file /etc/apache2/sites-available/000-default.conf only work if its having a symlink in sites-enabled folder.

You have done all right steps. Its may be problem of sysmlink of sites-available folder. You can either create a symlink or update 000-default.conf with AllowOverride None to AllowOverride All inside file /etc/apache2/sites-enabled/000-default.conf

0

Today I faced this exact same problem on an ubuntu EC2 instance.

This worked for me:

Place your .htaccess configuration inside the <IfModule ..> directive:

<IfModule mod_rewrite.c>
  RewriteEngine on
  # your config here
</IfModule>

Not sure if /var/www/html is actually taken into account by the server. Try changing this:

<Directory /var/www/html>
    # your current implementation
    AllowOverride All
</Directory>

for this one:

<Directory /var/www>
    # your current implementation
    AllowOverride All
</Directory>

This directive should already by there in your /etc/apache2/apache2.conf file.

If that does not work try to comment out your configuration, particularly the part that has the allow,deny and allow from all

<Directory /var/www>
    # your current implementation
    AllowOverride All
    # Order allow,deny # try to comment this one out 
    # allow from all # also this one
</Directory>

Last but not least, check that the rewrite a2enmod module is loaded as suggested by @kamal-kumar and do not forget to restart you apache.

This worked for me, hope this helps someone else :)

And Led
  • 13
  • 3