iis url重写用户友好的URL多​​个规则冲突

时间:2013-11-01 14:55:43

标签: iis url-rewriting iis-8 url-rewrite-module

我一直在尝试使用IIS 8上的url rewrite模块为我的两个cfm页面创建用户友好的URL。这就是说,由于规则之间的相似性,似乎存在某种冲突。

这是我想要实现的目标。以下几页:

www.mywebsite.com/news.cfm?category=microsoft
www.mywebsite.com/news.cfm?category=apple
etc

www.mywebsite.com/blog.cfm?title=sometitle
www.mywebsite.com/blog.cfm?title=sometitle
etc

应该是这样的:

www.mywebsite.com/news/microsoft
or this
www.mywebsite.com/microsoft

www.mywebsite.com/blog/sometitle
or this
www.mywebsite.com/sometitle

你明白了。

这是我的代码:

<rule name="RedirectUserFriendlyURL4" stopProcessing="true">
    <match url="^news\.cfm$" />
    <conditions>
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
        <add input="{QUERY_STRING}" pattern="^category=([^=&amp;]+)$" />
    </conditions>
    <action type="Redirect" url="news/{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL4" stopProcessing="true">
    <match url="^news/([^/]+)/?$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="news.cfm?category={R:1}" />
</rule>

<rule name="RedirectUserFriendlyURL5" stopProcessing="true">
    <match url="^blog\.cfm$" />
    <conditions>
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
        <add input="{QUERY_STRING}" pattern="^title=([^=&amp;]+)$" />
    </conditions>
    <action type="Redirect" url="blog/{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL5" stopProcessing="true">
    <match url="^blog/([^/]+)/?$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="blog.cfm?title={R:1}" />
</rule>

上述规则不能同时工作,并且两个页面都会重定向到第一个规则中设置的规则。这可以通过一个规则完成,还是需要使用两个?我该如何解决这个问题?我真的很感谢你对这个的帮助。我在Windows和IIS 8上使用ColdFusion 10。

0 个答案:

没有答案