SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot davejuk's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    Code:
    <?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)

  2. #2
    SitePoint Evangelist mumford1's Avatar
    Join Date
    Sep 2002
    Location
    UK
    Posts
    572
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

    Code:
    <?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

  3. #3
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,635
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •