Tuckey use-query-setting排除

时间:2016-02-23 12:26:30

标签: url-rewriting tuckey-urlrewrite-filter

我正在使用Tuckey重写过滤器来制定一些映射网址的规则。例如,我得到以下内容:

    <?xml version="1.0" encoding="utf-8"?>
       <urlrewrite use-query-string="true">
         <rule enabled="true">
            <note>Do not process URLs targeting fonts</note>
            <from>/*fonts*</from>
            <to last="true">-</to>
         </rule>

        <rule enabled="true">
            <note>Do not process calls to images</note>
            <from>/*images</from>
            <to last="true">-</to>
         </rule>

        <rule enabled="true">
            <note>Process the rest of the links </note>
            <from>/(.*)$</from>
           <to type="passthrough">/</to>
        </rule>
     </urlrewrite>

上面的规则允许我做的是,使用/ fonts和/ images以及其他所有东西(catchall)传递任何内容,然后重定向回主页。

我想要一个规则,不处理任何查询参数,让它直接传递。我尝试了各种正则表达式字符串,包括

     <rule enabled="true">
        <note>Do not process calls to /?*</note>
        <from>^/(.*)?</from>
        <to last="true">-</to>
      <rule>

但他们没有用。

基本上任何URL(例如https://example.com/promo/def)都会被重写回/(正在运行)。

不起作用的是https://example.com/promo/?def被重写为/并且没有被传递。那现在不行。

提前致谢。

1 个答案:

答案 0 :(得分:0)

您应该明确告诉tuckey过滤器您希望将查询字符串附加到目标URI。 可以在qsappend属性中使用<to>属性。

<rule enabled="true">
        <note>Do not process calls to /?*</note>
        <from>^/(.*)?</from>
        <to qsappend="true" last="true">/</to>
<rule>

如果您使用的版本低于4.0,则会有一个替代解决方案,明确地将query-string附加到目标URI。

<rule enabled="true">
            <note>Do not process calls to /?*</note>
            <from>^/(.*)?</from>
            <to last="true">/?%{query-string}</to>
<rule>