---
title: "tuckey urlrewrite 3.x的问题"
author: "somebody"
date: "2006-12-12T02:33:00Z"
tags: []
slug: "tuckey-urlrewrite-3-x"
draft: false
lastmod: "2006-12-12T02:33:00Z"
id: 45872
url: "https://jdkcn.iteye.com/blog/45872"
---

昨天晚上配置myblog的rewrite。发现一个奇怪的问题。由于现在使用的这个pjblog，为了让搜索引擎收录的连接有效。我想把原来的asp连接rewrite到我的新程序上面。所以有这样一条规则。

    &lt;rule&gt;  
        &lt;from&gt;^/article.asp\\?id=(.\*)$&lt;/from&gt;  
        &lt;to type="redirect"&gt;/entry/$1.jhtml&lt;/to&gt;  
    &lt;/rule&gt;

     但是我这样的连接总是匹配不到，只要去掉那个？就可以了。这个正则表达式是没有问题的。/article.asp?id=64是可以匹配的到的。  
    后来看3.0的manual (http://tuckey.org/urlrewrite/manual/3.0/)才发现原来是这个的问题。

### &lt;urlrewrite&gt; element

The top level element.

AttributePossible ValueExplanationdefault-match-type  
(optional)**regex** (default)All rules and thier conditions will be processed using the Java Regular Expression engine (unless `match-type` is specified on a rule).wildcardAll rules and thier conditions will be processed using the [Wildcard Expression engine](http://tuckey.org/urlrewrite/manual/3.0/#wildcard) (unless `match-type` is specified on a rule).decode-using  
(optional)**utf8** (default)When URL is decoded UTF-8 will be used.nullDo not decode.\[encoding]Any string representing a supported character encoding eg, ISO-8859-1. See [Java Charset Object](http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html) for more info. use-query-string  
(optional)**false** (default)The query string will *not* be appended to the url that the "from" element matches against.trueThe query string will be appended to the url that the "from" element matches against.use-context  
(optional)**false** (default)The context path will *not* be added to the url that the "from" element matches against.trueThe context path will be added to the url that the "from" element matches against.

就是那个use-query-string 的问题，默认的是不使用query-string就是把?后面的都忽略了。所以就不能匹配到了。只要在&lt;urlrewrite&gt;里面加一个属性就可以了。

&lt;urlrewrite use-query-string="true"&gt;  
    ![](http://www.blogjava.net/images/dot.gif)  
&lt;/urlrewrite&gt;

[![创造共用协议:署名,非商业,保持一致](http://leaf.jdk.cn/rights.gif)](http://www.creativecommons.cn/licenses/by-nc-sa/1.0/)   除经特别注明外,本文章版权归[**莫多泡泡**](http://jdkcn.com/)所有.  
署名,非商业用途,保持一致.   [somebody(莫多)](http://jdkcn.com/ "莫多泡泡")

![](http://www.blogjava.net/rory/aggbug/87151.html)

[莫多](http://www.blogjava.net/rory/) 2006-12-12 10:33 [发表评论](http://www.blogjava.net/rory/archive/2006/12/12/tuckey-urlrewrite_3-querystring-problem.html#Feedback)