0

Well, in my C# ASP .Net MVC application I have an URL:

controller/action?parameter=value

I need to redirect this URL in web.config using rewrite rules to:

controller/action?parameter=anotherValue

I've already configured the necessary section like below:

<rule name="Redirect" patternSyntax="Wildcard" stopProcessing="true">
    <match url="controller/action?parameter=value" />
    <action type="Redirect" url="controller/action?parameter=anotherValue" />
</rule>

But this rule just doesn't work. Also I've tried:

<rule name="Redirect" patternSyntax="Wildcard" stopProcessing="true">
    <match url="controller/action$" />
    <conditions>  
        <add input="{QUERY_STRING}" pattern="parameter=value" />  
    </conditions> 
    <action type="Redirect" url="controller/action?parameter=anotherValue" redirectType="Permanent" />

but this rule redirects me to: controller/action?parameter=value&parameter=anotherValue

How can I correctly perform this redirection?

4

1 回答 1

1

您的第一条规则上的?标志是有问题的,因为它是一个Wildcard字符。

尝试添加appendQueryString="false"到您的第二条规则:

<rule name="Redirect" stopProcessing="true">
    <match url="controller/action$" />
    <conditions>  
        <add input="{QUERY_STRING}" pattern="parameter=value" />  
    </conditions> 
    <action type="Redirect" url="controller/action?parameter=anotherValue" redirectType="Permanent" appendQueryString="false" />
</rule>
于 2013-06-05T15:10:12.333 回答