.htaccess not working in amazon ec2 ubuntu instance

限于喜欢 提交于 2019-12-03 16:00:28

This happens because the rewrite module doesn’t come enabled by default for security reasons.

Create a new file called rewrite.conf in /etc/apache2/mods-enabled in the file put this line LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

Now reload server sudo service apache2 restart

This worked for me and hopefully for you, but I don’t advice this for production servers. This is information for regular Ubuntu users not for a live server.

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

You need to check whether the mod rewrite module is enabled or not first.

Tried everything and nothing worked...

2 hours later.. Finally fixed it.

So first the things to rule out.

  1. Make sure that you have made the changes in /etc/apache2/apache2.conf and in /etc/apache2/sites-enabled/000-default.conf that everyone is talking about... (AllowOverride All and AccessFileName .htaccess must not be commented out)

  2. Make sure that the Directory /var/www/html is pointing to the right folder. Some times it has /html and some times it's just /var/www (however it must not end in / i think, but that might not matter.)

    1. Finally, and this is what worked for me. Restart the whole server, not just Apache. I figured out that this was my problem, after i tried stopping apache2 (service apache2 stop) and I was still able to access my website. So I did a full reboot and then all the changes I have been making for the last 2 hours, finally kicked in.

Success :)

The problem is by default in apache installed on Ubuntu doesn't have .htaccess enabled so first you have to manually enable it in a config file and restart apache.

Here are the steps.

1) Login to your EC2 instance with SSH.

ssh -i "Yourkey.pem" ubuntu@yourpublicip

2) Enable Mode Rewrite, this is just incase if it's not enabled.

sudo a2enmod rewrite

3) Go to the following directory.

cd /etc/apache2/sites-available

If you use LS command here you will see the following file.

000-default.conf

That's the file with default apache configuration which is applied to your sites in /var/www/html folder.

4) Open this file for editing.

sudo nano 000-default.conf

5) Add following lines after DocumentRoot /var/www/html line.

Options FollowSymLinks AllowOverride All Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all

6) Save the file and restart the apache.

sudo service apache2 restart

that's it and now your .htaccess file will work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!