针对使用代理服务器比如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