URL rewrite not working

Discussion in 'Domain names / DNS' started by stumac, Feb 11, 2016.

Tags:
  1. The usual scenario.
    I have a domain elsewhere and my code is hosted here.
    So the Name Servers have been changed at the domain end and a domain pointer purchased here.
    Which gets me to the point where the domain gives me the discountasp.net welcome page so that works.

    Now I'm trying to point this domain to a subfolder and using a rewrite rule in a web config file placed in my root directory.
    My code is as follows:
    Code:
    <?xml version="1.0"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="aerialworks.uk" stopProcessing="true">
              <match url=".*" />
              <conditions>
                <add input="{HTTP_HOST}" pattern="^(www.)?aerialworks.uk" />
              </conditions>
              <action type="Redirect" url="\aerialworks\ {R:0}" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    Typing in the domain name brings up an error: "The page isn't redirecting properly"
    And the url is now: "http://www.aerialworks.uk/\aerialworks\aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/aerialworks/"

    Where have I gone wrong?
    Thanks in advance!
     
  2. martino

    martino DiscountASP.NET Staff

    Try using the following code I got from: http://weblogs.asp.net/owscott/iis-url-rewrite-hosting-multiple-domains-under-one-site

    Code:
    <rewrite>
    
        <rules>
    
            <rule name="aerialworks.uk" stopProcessing="true">
    
                <match url=".*" />
    
                <conditions>
    
                    <add input="{HTTP_HOST}" pattern="^(www.)?aerialworks.uk" />
    
                    <add input="{PATH_INFO}" pattern="^/aerialworks/" negate="true" />
    
                </conditions>
    
                <action type="Rewrite" url="\aerialworks\{R:0}" />
    
            </rule>
    
        </rules>
    
    </rewrite>
     
    stumac and mjp like this.
  3. Thanks Martino. The discountasp staff are always the best when it comes to supporting their customers!

    Just tried adding the PATH_INFO input and now getting a 404 Page Not Found error and the url is now showing as "http://www.aerialworks.uk:80/aerial...ialworks/aerialworks/aerialworks/aerialworks/"

    The 404 gives a bit more info in so much as it shows the phsical path...........which is still off.
    "E:\web\oneworldim0\htdocs\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\aerialworks\"

    So in a way it's possibly a step forward but now it's including a port number in the url. And of course the repeated patterns.

    Any other ideas I could try?
     
    Last edited: Feb 12, 2016
  4. Please ignore the above post.
    The changes Martino suggested were correct. BUT, remember to clear your BROWSER CACHE to see any effects of changes.
    This happened to me in both Chrome and Firefox.
    The only other change I had to make was to change
    Code:
    <action type="Rewrite" url="\aerialworks\{R:0}" />
    to
    Code:
    <action type="Redirect" url="aerialworks/{R:0}" />
    Works like a charm.
    Thanks agan Martino.
     
    martino, RayH and mjp like this.
  5. martino

    martino DiscountASP.NET Staff

    Awesome! Glad you figured that part out and thanks for the tip. I'm sure it will help a lot of other people too :D
     

Share This Page