Today I was working on a client’s Amazon Linux EC2 web server and had to enable mod_rewrite. This tutorial should help anyone else trying to do the same thing.
I read online that mod_rewrite was probably the culprit. Before assuming this, you should make sure your .htaccess file is working properly with correct permissions. You can simply make sure the file exists and set permissions to 777, test, then set your permissions back as they were to make your file secure once again. If that doesn’t do it, then check your mod_rewrite using the following procedure:
- make a info.php file with only this for content: “<?php phpinfo(); ?>” and save it as info.php. Upload to your root directory and go to your domain name/info.php and search for the text “mod_rewrite” if you find it in the php info file, then your mod_rewrite is enabled. If not, then enable it.
- To enable mod_rewrite, try the command line command: sudo a2enmod rewrite
If mod_rewite was enabled then something else is wrong. Check your etc/httpd/conf/httpd.conf file. It should have the following in it:
AllowOverride All
Basically, you’ll be adding All insted of None to AllowOverride, you do not want to edit the main directory configuration, you want to edit the one that looks like this:
<Directory “/var/www/html”>
Not:
<Directory />
Then restart Apache with:
sudo service httpd restart
from the command line.
Now, if you are using WordPress and trying to enable Permalinks as I was, next, go to your wp-admin page and go to settings/permalinks and change from default to post-name and click the save button to save the changes and try again. If you did this before making mod_rewrite fixes, you may need to change back to default, save, and then change to post-name again and save one last time for the settings to work.
Good Luck!
thanks a lot
Thanks for this! Nice coverage, as my mod_rewrite was already active, so the AllowOverride did the trick. Good, clear writing.
Thanks again. Was quite helpful!
Thanks for the very clear directions. This is just what I needed to get WordPress multi site with sub directories working. Was a long time looking for this.
Been pulling my hair out on this one!!! Thank you 🙂
Thanks for the tip here, turns out AllowOveride All was exactly what I needed as well… thanks!
Thanks! Just what I was missing.
Thank you for the help!! This was what I needed. 😀 I appreciate you helping out 🙂
I think there is a typo, that would be nice to double check. a2enmod is a command for Debian based distributions, not for Redhat based distributions.
Thank you so much for this. I was struggling for hours on this one.
Thanks a ton mate! Was struggling with this for hours.
THANK YOU!!!
I have almost tears on my face after my website start working. thank you very much dude
Superb..I wasted 2 days to crack this. Atlast i got the answer from here..
Thanks!!!
THANK YOU!!
I was struggling for whole day on this one.
sudo a2enmod rewrite is for Debain, For linux let me know how to verify or enable the mod_rewrite. Struggling for the same
Thank you!! Your article was a life saver!!
Thanks 🙂
very useful article
“httpd restart” – the life saver for me!
Thank you so much for this nice post 🙂
couldn’t get the sudo a2enmod rewrite command to work, BUT great tip on changing the etc/httpd/conf/httpd.conf file to AllowOverride All !
Wow, thanks a lot!
You saved my life!!!!
Hey there deliah!