URL在主目录iis中重写查询

时间:2013-02-25 19:56:21

标签: iis iis-7 url-rewriting web-config rewrite

我正在尝试使用iis7 url重写来处理主目录中的查询。最终目标是让它将index.php追加到查询字符串的开头。我尝试的所有内容都以500错误结束。我做错了什么?

<rule name="post preview fix" patternSyntax="ECMAScript">
    <match url="^\?p=([0-9]+)&preview=true"  />
    <action type="Rewrite" url="index.php?p={R:1}&preview=true"  />
</rule>

1 个答案:

答案 0 :(得分:0)

由于您希望将规则建立在查询字符串上,因此必须使用这些条件 这样的事情应该做:

<rule name="post preview fix" stopProcessing="true">
    <match url="^index.php$" negate="true" />
    <conditions>
        <add input="{QUERY_STRING}" pattern="^p=([0-9]+)&preview=true" />
    </conditions>
    <action type="Rewrite" url="index.php" />
</rule>

如果请求的页面不是index.php且查询字符串与^p=([0-9]+)&preview=true匹配,则触发rwrite。
<{1}}选项默认设置为true,因此无需设置它。

相关问题