Why is this rewrite redirecting?

Discussion in 'Site Programming, Development and Design' started by with, Apr 16, 2011.

  1. I'm pointing an offsite domain at my basic account & trying to host it in a subfolder. Folder structure looks like this:

    root\offsite\alt1

    Because offsite domains point to root by default, I've setup a rewrite to get this offsite domain:

    http://alt1.com

    serving files from this location:

    root\offsite\alt1

    And I want the "offset\alt1" pathing hidden from the browser.

    So here's the rewrite:

    Code:
    <xml version="1.0" encoding="UTF-8"?>
        <configuration>
            <system.webServer>
                <rewrite>
                    <rules>
                        <rule name="Test" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTP_HOST}" pattern="(^|\.)alt1\.com$" />
                        </conditions>
                        <action type="Rewrite" url="offsite/alt1/{R:1}" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    This sort of works. If I browse to "http://alt1.com"

    I get a 200 OK response, I'm served the default document from "root\offsitet\alt1", and the address bar shows "http://alt1.com/". Seems to work great.

    Then I try browsing to http://alt1.com/somepath

    I get a 301 Moved Permanently response
    Location: http://alt1.com/offsite/alt1/somepath/

    Then I get a 404 trying to follow through with the redirect:

    Requested URL
    http://alt1.com:80/offsite/alt1/offsite/alt1/somepath/

    Physical Path
    E:\web\root\offsite\alt1\offsite\alt1\somepath\

    It looks to me like this would be working if not for that 301 redirect, but I don't understand why there's a 301 redirect happening here.

    The redirect's not coming from a content page, since I don't have any content pushed to this site other than test html pages that contain basically nothing.

    Any idea what I'm doing wrong here?
     
  2. Ray

    Ray

    It sounds like you have some other redirect script occurring in the background. Try running a telnet test to verify it. Open MSDOS and type this

    telnet alt1.com 80

    GET http://alt1.com/ HTTP/1.0

    See what you get.
     
  3. Think I found conflict. I don't quite follow the logic flow here but seems to matter whether there's a slash after the domain.

    GET alt.com (no slash) = 200

    GET alt.com/ (with a slash, including any pathing) = 301, etc.

    I managed to fix this by adding a redirect rule forcing a naked "alt1.com" (no slash) to "alt1.com/" (with a slash). Everything seems happy now.
     

Share This Page