如何在ubuntu的LAMP中启用mod_rewrite? [英] How to enable mod_rewrite in LAMP on ubuntu?

查看:56
本文介绍了如何在ubuntu的LAMP中启用mod_rewrite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在计算机上使用Ubuntu 12.04 LTS linux.我已经在上面安装了LAMP.现在,我要启用mod_rewrite模块.我做了很多Google尝试了很多技巧,但无法启用mod_rewrite.谁能帮助我启用mod_rewrite?预先感谢.

I'm using Ubuntu 12.04 LTS linux on my machine. I've already installed LAMP on it. Now I want to enable the mod_rewrite module. I did google a lot and tried lots of tricks but couldn't be able to enable mod_rewrite. Can anyone help me to enable the mod_rewrite? Thanks in advance.

推荐答案

TL; DR版本-在您的终端上执行以下操作:

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)

必要时将"AllowOverride None"替换为"AllowOverride all"

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

sudo service apache2 restart    ///restarts apache

在/etc/apache2/sites-available中编辑您的虚拟主机条目,然后将AllowOverride All添加到DocumentRoot.您的虚拟主机最终应该看起来像这样:

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.

这篇关于如何在ubuntu的LAMP中启用mod_rewrite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆