Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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" />
share|improve this answer
    
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: domain.com/… –  Saikios May 8 '12 at 22:36
    
@Saikios - glad it worked. Just ask a new question on the site. –  Kev May 8 '12 at 22:40
    
done @kev serverfault.com/questions/387323/… –  Saikios May 9 '12 at 3: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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.