Web.config URL rewrite rules work but not 301 redirects

I have just replaced a site with a new Wordpress based site. Everything works great except I can’t get 301 redirects to work.

This is the start of my Web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>

      <rewrite>
        <rules>

          <rule name="Contact" stopProcessing="true">
            <match url="/contact\\.aspx" />
            <action type="Redirect" url="/contact/" />
          </rule>

          <rule name="Main Rule" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAll">
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="index.php" />
          </rule>

        </rules>
      </rewrite>

Simple enough, right? The rewrite for Wordpress works fine but the redirect seems to be being ignored.

This really has me stumped. Any help greatly appreciated.

P.S. I am using IIS 7 (Server 2003)

Hi

I am to have similar problem. I have set up a Wordpress site that is located on a Windows server. I am trying to add 301 ReDirects to my web.config file, everything I try does not work!

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
            <rule name="wordpress" patternSyntax="Wildcard">
                <match url="*" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                <action type="Rewrite" url="index.php" />
            </rule>
            
                <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
                    <match url="^algarve/parque_floresta$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://www.siteaddress.co.uk/algarve/algarve-resorts/parque-da-floresta/" />
                </rule>
                
                <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
                    <match url="^algarve/quinta_roque\\.htm$" />
                    <conditions>
                        <add input="{REQUEST_METHOD}" negate="true" pattern="^POST$" />
                    </conditions>
                    <action type="Redirect" url="algarve/quinta_roque" appendQueryString="false" redirectType="Permanent" />
                </rule>
                <rule name="RewriteUserFriendlyURL2" stopProcessing="true">
                    <match url="^algarve/quinta_roque$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="http://www.siteaddress.co.uk/algarve/algarve-resorts/quinta-da-sao-roque/" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Could someone please help me with this and let me know what is the correct syntax I need to add to the web.config file to set up 301 ReDirects.

Really appreciate any help!

Thanks

Looks like your 301 never happens as you are catching everything that isn’t a file or directory and sending it to wp then stopping processing.

Moving your rule above should help. I think you can also explicitly define order precedence but I’m foggy on specific syntax.