Apache下urlrewrite配置

针对使用代理服务器比如apache服务器的应用使用urlrewrite与struts2进行整合的方式将行不通,当你访问一个你定义的规则的xx.html时,apache找不到对应的html文件将会返回到404页面,即你的配置规则apache根本就不认可。因此针对这种情况的urlrewrite需要在apache中进行配置,具体如下

在httpd.conf中的

<VirtualHost *:80>
    ServerAdmin wwwwwwwwwww@service.com 
    DocumentRoot /home/app 
    ServerName www.sd009.com 
    ErrorLog logs/xxxxx.error_log 
    CustomLog logs/xxxxx.access_log common 
</VirtualHost>

添加如下红色标记的内容

<VirtualHost *:80>
    ServerAdmin wwwwwwwwwww@service.com 
    DocumentRoot /home/app 
    ServerName www.sd009.com
    RewriteEngine On

    RewriteRule /addComment.html /user/ saveComment .do [PT]
    RewriteRule /comment-([0-9]+).html /user/queryComment.do?pId=$1 [PT]
    RewriteRule /comment-([0-9]+)-([a-z]+)-([0-9]+).html /user/
queryComment .do? pId =$1&pMethod=$2&cPage=$3 [PT]
    ErrorLog logs/xxxxx.error_log 
    CustomLog logs/xxxxx.access_log common 
</VirtualHost>

 

配置说明

RewriteRule /saveComment.html /user/saveComment.do [PT]

当访问:www.sd009.com/addComment.html实际访问的是www.sd009.com/user/saveComment.do

RewriteRule /comment-([0-9]+).html /user/queryComment.do?pId=$1 [PT]

当访问www.sd009.com/comment-20.html 实际访问的是www.sd009.com/user/queryComment.do?pId=20

RewriteRule /comment-([0-9]+)-([a-z]+)-([0-9]+).html /user/queryComment.do?pId=$1&pMethod=$2&cPage=$3

当访问www.sd009.com/comment-30-n-10html

实际访问的是www.sd009.com/user/queryComment.do?pId=30&pMethod=n&cPage=10

配置完成后记得重启服务器。

参考资料:

http://blog.sina.com.cn/s/blog_5dc960cd0100fpmi.html

http://www.chinaunix.net/jh/13/286614.html

http://www.jutsoft.cn/bbs/post/view?bid=67&id=143184

http://apps.hi.baidu.com/share/detail/7138177


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值