---
title: "apache下安装mod_rewrite模块"
author: "skydream"
date: "2007-12-05T15:21:08Z"
tags: ["Apache"]
categories: ["企业架构"]
slug: "apache-mod-rewrite"
draft: false
lastmod: "2007-12-05T15:21:08Z"
id: 146197
url: "https://skydream.iteye.com/blog/146197"
---

apache下安装mod_rewrite模块

在网上找了一些apache下安装mod_rewrite模块的文章，说得都很轻巧，但是俺一路碰壁，怎么都出不来。整理了一下，以后再来研究。

一. 编译rewrite模块

在apache 2.0.61下按照rewrite模块失败，目前还没有找到原因。
使用apache 2.2.6按照rewrite模块，采用的方式是在编译apache前，configure增加参数

./configure --prefix=/data/aoxj/artest/apache --enable-so  --enable-rewrite=shared
然后再执行make;make install可以成功的编译出mod_rewrite.so

(在2.0.61下失败，只编译出mod_rewrite.a文件，原因不明)


尝试在2.0.61下用以下设置编译apache都没有成功。

./configure --prefix=/data/aoxj/artest/apache --enable-so --enable-rewrite --enable-shared=rewrite

./configure --prefix=/data/aoxj/artest/apache --enable-module=so --enable-module=rewrite --enable-shared=rewrite
这句是网络硬盘系列编译apache时使用的，在apache1.*上可以打包出mod_rewrite.so。
但是在apache2.0.61上失败。

（估计是参数写法各个版本不同，以后有时间再来研究）。


二. 配置apache

在apache的配置文件apache/conf/httpd.conf中增加以下内容：

LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteLog  logs/rewrite.log
RewriteLogLevel 3

#RewriteRule ^/~jid=[^/]*/(.*) /$1 [PT,L]

RewriteRule中测试过上面的^/~jid=[^/]*/(.*) /$1 [PT,L]，apache会将
http://10.3.2.35:11280/~jid=abcMLHHOULJHLKJ/wmail/welcome.action
这样的请求，改写为
http://10.3.2.35:11280/wmail/welcome.action
