0
votes

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?

1

1 Answers

1
votes

The ? sign on your first rule is problematic, since it's a Wildcard character.

Try to add appendQueryString="false" to your second rule:

<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>