来源于:http://trac.seagullproject.org/wiki/Installation/SettingUpModRewrite

安装 mod_rewrite 模块

虽然大部分的服务器默认安装并启用了这个模块,但是也有一些例外

模块载入了吗?

有时候该模块被编译成 httpd 二进制流,如果是这样的话,你可以通过下列命令查看该模块是否被载入了

httpd -l

如果列表中没有,它有可能是被动态载入的。在这种情况下你可以通过下列代码的输出来查看

<?php phpinfo(); ?>

如果你是自己编译安装Apache, 你只需简单的把下列这行添加到你的配置文件(注:这样就可以在Apache启动时自动载入该模块)

./configure --enable-module=rewrite

如果你使用的是Apache的分支版本,如,Fedora Core(红帽子Linux服务器版),你必须安装相关的devel工具

yum install apache2-devel

这样 mod_rewrite 模块就可以用了。

现在 mod_rewrite 是载入了,但它还不能工作

这是很典型的,意思是说默认的Apache配置不允许使用自定义的 .htaccess 文件。 你要将

AllowOverride None

改为

AllowOverride All

你只要编辑httpd.conf文件然后搜索AllowOverride来修改。 你搜索到的第一个结果并不是你要找的,因为它作用于根目录。

<Directory />

这是第二个作用Web根目录的属性配置, 你可以修改这个属性,但是你可能不想让你的所有网站都允许mod_rewrite模块操作(如写操作)。 当然了你可以为你的某个特定站点另外创建一个目录节点,

<Directory /path/to/your/site>
  Options FollowSymLinks
  AllowOverride All
</Directory>

保存修改后,重新启动apache服务器以使用修改的设置生效。

 
installation/settingupmodrewrite.txt · 最后更改: 2010/05/30 00:21 (外部编辑)
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2