« Previous Next »

Thread: Very strange URL rewrite problem?

Last post 10-05-2009 10:53 AM by mcdotnet. 3 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (4 items)

Sort Posts:

  • 10-05-2009, 6:42 AM

    • mcdotnet
    • Not Ranked
    • Joined on 09-10-2008, 8:41 AM
    • Posts 8

    Very strange URL rewrite problem?

    I am rewriting the url http://www.tworiverstaines.co.uk to http://www.tworiverstaines.co.uk/TwoRivers/ using this rule:
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^www.tworiverstaines.co.uk$" />
    </conditions>
    <action type="Rewrite" url="TwoRivers/{PATH_INFO}" />

    When the site first loads the rewrite works correctly displaying Default.aspx with all the hyperlinks working correctly including the path to the App_Themes folder etc.

    However when you click on the homepage link (or any other) when the Default.aspx (or page requested) loads all the hyperlinks and paths are altered from /Default.aspx to /TwoRivers/Default.aspx so when you click on a hyperlink it is broken as the rewrite rule will take you to www.tworiverstaines.co.uk/TwoRivers/TwoRivers/Default.aspx.

    To prevent the 404 error I have added a local rule to rewrite /TwoRivers/TwoRivers/ to /TwoRivers/ however this isn't a good solution as the URL in the browser shows the subfolder and pages become available at /Default.aspx and /TwoRivers/Default.aspx which could present duplicate content issues with search engines.

    Does anyone have any idea why this is happening?

    The site can be accessed at http://www.tworiverstaines.co.uk

    I am displaying the header information at the bottom of each page to display the paths. The web server is running IIS 7 ASP.NET 3.5 SP1.

  • 10-05-2009, 8:35 AM In reply to

    Re: Very strange URL rewrite problem?

    McDotNet:
    Does anyone have any idea why this is happening?

    Sure.  Because you're telling it to.  :)

    You rewrite www.tworiverstaines.co.uk to www.tworiverstaines.co.uk/TwoRivers/ plus the path info.  Whci works to change www.tworiverstaines.co.uk/Default.aspx to www.tworiverstaines.co.uk/TwoRivers/Default.aspx.  And then it changes www.tworiverstaines.co.uk/TwoRivers/Default.aspx to www.tworiverstaines.co.uk/TwoRivers/TwoRivers/Default.aspx, just as you configured it.

    The problem is it takes any URL that begins with www.tworiverstaines.co.uk and adds /TwoRivers/ to it, followed by the rest of the URL after the host/domain name.  You don't want to do that, you only want to rewrite the URL if it isn't www.tworiverstaines.co.uk/TwoRivers/.  Change from a condition where the host name is www.tworiverstaines.co.uk to a condition where the URL is not www.tworiverstaines.co.uk/TwoRivers/.

    Jeff

    Look for Wrox's new book Professional IIS 7 in your local bookstore, or order now at Amazon.com
  • 10-05-2009, 9:49 AM In reply to

    • mcdotnet
    • Not Ranked
    • Joined on 09-10-2008, 8:41 AM
    • Posts 8

    Re: Very strange URL rewrite problem?

    Hi Jeff I think the only strange part of the problem is me! however I am still confused I have changed my rule to the below which doesn't give me the /TwoRivers/TwoRivers/ problem but all of the links to my resources are broken i.e. app_themes, scripts etc.

    <rule name="tworiverstaines.co.uk" stopProcessing="false">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^www.tworiverstaines.co.uk(.*)$" />
    </conditions>
    <action type="Rewrite" url="TwoRivers{C:1}" />
    </rule>

    Would you be able to help create a rule that allowed me to visit my website contained in a subfolder "TwoRivers/" when visiting www.tworiverstaines.co.uk without showing the subfolder in the browser address bar?

    Thanks

     

  • 10-05-2009, 10:53 AM In reply to

    • mcdotnet
    • Not Ranked
    • Joined on 09-10-2008, 8:41 AM
    • Posts 8

    Re: Very strange URL rewrite problem?

    This is my latest stab at a rule to prevent the /TwoRivers/TwoRivers/ problem but it hasn't done the trick:

    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
    <add input="{URL}" negate="true" pattern="^www.tworiverstaines.co.uk/TwoRivers/.*$" />
    <add input="{HTTP_HOST}" pattern="^www.tworiverstaines.co.uk$" />
    </conditions>
    <action type="Rewrite" url="TwoRivers/{PATH_INFO}" />

Page 1 of 1 (4 items)
Microsoft Communities