【问题标题】:How to enable mod_rewrite in LAMP on ubuntu? [closed]如何在 ubuntu 上的 LAMP 中启用 mod_rewrite? [关闭]
【发布时间】:2013-07-18 16:38:09
【问题描述】:

我在我的机器上使用 Ubuntu 12.04 LTS linux。我已经在上面安装了 LAMP。现在我想启用 mod_rewrite 模块。我做了很多谷歌并尝试了很多技巧,但无法启用 mod_rewrite。谁能帮我启用 mod_rewrite?提前致谢。

【问题讨论】:

    标签: php mod-rewrite ubuntu ubuntu-12.04 lamp


    【解决方案1】:

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

    sudo a2enmod rewrite
    

    您还可以使用以下方法检查 mod 重写是否已启用:

    apache2ctl -M
    

    【讨论】:

      【解决方案2】:

      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)
      

      根据需要将出现的“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>
      

      虽然这不适合生产环境,但它适用于本地开发。

      【讨论】:

      • :非常感谢,您提供了如此简单的语言,并详细描述了每个步骤。我已接受并赞成您的回答。
      • @mike - 很好的答案,但是你还提到了在生产环境中要做什么或提供一些链接来查找此类情况
      • @StacyJ 对于这个问题来说这有点离题。彻底阅读 /etc/apache2/apache2.conf 或 httpd.conf cmets。查看httpd.apache.org/docs/current/misc/security_tips.htmlhelp.ubuntu.com/12.04/serverguide/httpd.html 了解更多信息
      • “TL;DR 版本”是什么意思?
      猜你喜欢
      • 2016-08-18
      • 2016-04-05
      • 1970-01-01
      • 2011-05-02
      • 1970-01-01
      • 1970-01-01
      • 2012-05-02
      • 1970-01-01
      • 2011-02-25
      相关资源
      最近更新 更多