Neio Notes Share knowledge and experience with you

9Oct/091

为Apache2添加URL重写

上一次碰Apache已经是好几年前的事情了,也很久没有弄过PHP。现在准备重开博客,在自己的Ubuntu上先安装了WordPress,照例要开启URL重写。

现在的Apache配置比过去方便多了,国内文章中关于rewrite的配置一大堆,但都显得过时,或者过于麻烦。所以我单列这篇出来,希望对初学者有所帮助。

过去,一般要打开apache2.conf或者httpd.conf,在里面使用LoadModule 来加载rewrite_module,现在可以不用这么写了。

比较简单的方法是用:

"a2enmod rewrite"

这样一条命令就可以搞定。当然,如果你当前不是Ubuntu的管理员,前面记得加上“sudo”。

然后记得重启下Apache服务器。(/etc/init.d/apache2 restart

然后在你要允许使用rewrite的站点配置中,例如安装apache的时候的默认站点:

sudo gedit /etc/apache2/site-enabled/000-default

把里面的AllowOverride None 改为 AllowOverride all

DocumentRoot /var/www/

<Directory />

Options FollowSymLinks

AllowOverride all

</Directory>

<Directory /var/www/>

Options FollowSymLinks

AllowOverride all

Order allow, deny

allow from all

</Directory>

Page 2 of 212