How to enable mod_rewrite in LAMP on ubuntu? [closed]

て烟熏妆下的殇ゞ 提交于 2019-11-30 00:25:58

TL;DR version -- do the following in your terminal:

sudo a2enmod rewrite && sudo service apache2 restart

With explanations -- do the following in your terminal:

ls -l /etc/apache2/mods-available/rewrite.load    ///if it prints out rewrite.load, it's there and ready to go

sudo a2enmod rewrite   //enables the mod

ls -l /etc/apache2/mods-enabled/rewrite.load // shows created symlink

sudo vi /etc/apache2/sites-available/default   //opens the file in vi (you can also use vim or nano)

Replace occurrences of "AllowOverride None" with "AllowOverride all" as necessary

sudo service apache2 restart    ///restarts apache

Edit your virtual host entry in /etc/apache2/sites-available and add AllowOverride All to the DocumentRoot. Your virtual host should ultimately look something like this:

<VirtualHost *:80>
  ServerName example.com
  DocumentRoot /var/www/vhosts/example.com
  <Directory /var/www/vhosts/example.com>
    AllowOverride all
  </Directory>
</VirtualHost>

Although this isn't suitable for production environments, it works just fine for local development.

You didn't mention what commands did you try, so I will start with the basic one:

sudo a2enmod rewrite

You can also check if mod rewrite is already enable using:

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