Apache如何使用rewrite模块

问题
在虚拟主机站点中,有些站点需要rewrite URL支持。

解决方案
1. 需要在apache的配置文件httpd.conf中加入相应配置:

Apache-1.3.x版本,在/usr/prima/apache_ssl/conf/httpd.conf里加入:
LoadModule rewrite_module libexec/mod_rewrite.so
AddModule mod_rewrite.c

Apache-2.x版本,在/etc/httpd/conf/httpd.conf里加入:
LoadModule rewrite_module modules/mod_rewrite.so

2. 重启apache:

Apache-1.3.x:
/usr/prima/apache_ssl/bin/apachectl restart

Apache-2.x:
/etc/init.d/httpd restart

3. 在/usr/prima/etc/httpd/virtual.conf的需要.htaccess和rewrite功能的站点配置中
加入:
<Directory /www/users/xxx>
AllowOverride Options FileInfo
</Directory>
注意FileInfo,这是支持RewriteEngine的关键

4. 之后只需要用户自行在需要.htaccess的目录中配置.htaccess文件了,如需要用
rewrite模块,加入如下:

<IfModule mod_rewrite.c>
RewriteEngine On
[rewrite配置]
</IfModule>

5. Windows下可以先将.htaccess内容写入一个文本文件中,然后将此文本文件上传到服
务器需要.htaccess的目录中,改名为.htaccess即可。

按照以上配置,即可使用rewrite模块。

相关推荐