Php 如何在ubuntu上的LAMP中启用mod_重写?

Php 如何在ubuntu上的LAMP中启用mod_重写?,php,mod-rewrite,ubuntu,ubuntu-12.04,lamp,Php,Mod Rewrite,Ubuntu,Ubuntu 12.04,Lamp,我正在我的机器上使用Ubuntu12.04 LTS linux。我已经把灯装上了。现在我想启用mod_重写模块。我用谷歌搜索了很多次,尝试了很多技巧,但无法启用mod_重写。有人能帮我启用mod_重写吗?提前感谢。您没有提到您尝试了哪些命令,因此我将从基本命令开始: sudo a2enmod rewrite 您还可以使用以下方法检查mod rewrite是否已启用: apache2ctl -M TL;DR版本--在终端中执行以下操作: sudo a2enmod rewrite &&a

我正在我的机器上使用Ubuntu12.04 LTS linux。我已经把灯装上了。现在我想启用mod_重写模块。我用谷歌搜索了很多次,尝试了很多技巧,但无法启用mod_重写。有人能帮我启用mod_重写吗?提前感谢。

您没有提到您尝试了哪些命令,因此我将从基本命令开始:

sudo a2enmod rewrite
您还可以使用以下方法检查mod rewrite是否已启用:

apache2ctl -M
TL;DR版本--在终端中执行以下操作:

sudo a2enmod rewrite && sudo service apache2 restart
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)
带说明--在终端中执行以下操作:

sudo a2enmod rewrite && sudo service apache2 restart
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)
必要时,将出现的“AllowOverride None”替换为“AllowOverride all”

sudo service apache2 restart    ///restarts apache
在/etc/apache2/sites available中编辑虚拟主机条目,并将
AllowOverride All
添加到DocumentRoot。您的虚拟主机最终应该是这样的:

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

ServerName example.com
DocumentRoot/var/www/vhosts/example.com
允许超越所有

尽管这不适用于生产环境,但对于本地开发来说效果很好。

:非常感谢您,您可以用如此简单的语言描述每个步骤。我已经接受并投票支持您的答案。@mike-ya回答得很好,但您是否也提到了在生产环境中应该做什么,或者提供了一些链接来查找这些问题cases@StacyJ这对于这个问题来说有点离题。彻底阅读/etc/apache2/apache2.conf或httpd.conf注释。检查并获取更多信息“TL;DR版本”是什么意思?