2

The idea is to add a rule to my iis (version 7) to redirect this

http://www.mydomain.com/folder/Default.aspx?&variable1=eeee&variable2=aaa

to:

http://www.mydomain.com/folder/Default.aspx?&variable1=ffff&variable2=gggg

But it have to be only with this specific url and all the urls must mantain the same thing

I read this article http://blogs.iis.net/bills/archive/2008/05/31/urlrewrite-module-for-iis7.aspx but is for patterns and all url and this is an specific url

Thanks!

Saikios
  • 133
  • 1
  • 6

1 Answers1

2

Try this:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="MyRule" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^folder/Default.aspx$" />
          <action 
              type="Redirect" 
              url="folder/Default.aspx?&amp;variable1=ffff&amp;variable2=gggg" 
              appendQueryString="false" 
              redirectType="Found" /> 

          <conditions logicalGrouping="MatchAny">
            <add input="{QUERY_STRING}" 
                 pattern="^&amp;variable1=eeee&amp;variable2=aaa$" />

            <add input="{QUERY_STRING}" 
                 pattern="^variable1=eeee&amp;variable2=aaa$" />
          </conditions>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

Set the redirectType attribute in the <action> element to one of:

  • Permanent for a 301 Permanent redirect
  • Found for a 302 Found redirect

This covers the possibility of the query string being:

&variable1=eeee&variable2=aaa - as per your example, with a leading ampersand

or with the leading ampersand:

variable1=eeee&variable2=aaa

If you just want a straight rewrite without doing a redirect then change the <action> element to:

<action type="Rewrite" 
        url="folder/Default.aspx?&amp;variable1=ffff&amp;variable2=gggg" 
        appendQueryString="false" />
Kev
  • 7,877
  • 18
  • 81
  • 108
  • Hi Kev, it worked great!, can I ask you one more favor? I have a problem with some special characters on one of the urls: http://domain.com/login.aspx?TargetURL=%2fxxx%2fDefault.aspx%3f%26RoomID%3dyyy%26GameID%3dxxx&RoomID=yyy&GameID=xxx – Saikios May 08 '12 at 22:36
  • @Saikios - glad it worked. Just ask a new question on the site. – Kev May 08 '12 at 22:40
  • done @kev http://serverfault.com/questions/387323/probelm-with-encoding-on-web-config – Saikios May 09 '12 at 03:04
  • If your IIS web site's root isn't an ASP.Net application, do you need to stick the rewrite rules in machine.config? – Remi Despres-Smyth Sep 23 '13 at 17:58