Unable to use {HTTP_HOST} for multiple rewrite rules in web.config file with GoDaddy Hosting - IIS 7.0

I ran into a weird problem creating some rewrite rules for my site, which is hosted by GoDaddy. I can create one rewrite rule using variables {HTTP_HOST}

or {SERVER_NAME}

, but at the time of adding the second rule, it looks like this: {HTTP_HOST}

/ {SERVER_NAME}

does not return a value (I think), so my code doesn't work.

After a little error, I found work around the problem (which I will add at the bottom). I am asking this question because I would like to:

  • Understand the reason for this behavior
  • Know if this happens to someone else.
  • Find out if my approach is wrong or if I missed something this works

Because of this issue, I decided to clear the entire web.config file for testing and only have the rewrite rules. I tried several changes, but I can't remember all of them at the moment, so I'll add as many as I remember.

Question

This code works

    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Mask myFile.xml" stopProcessing="true" patternSyntax="Wildcard">
                    <!-- This rule always -->
                    <match url="*" />
                    <conditions>
                        <add input="{REQUEST_URI}" pattern="/myFile.xml" />
                    </conditions>
                    <action type="Rewrite" url="/SiteDependentFiles/{HTTP_HOST}/new_myFile.xml"  appendQueryString="false"/>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

      

This code is not (see notes inside code)

    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Mask myFile.xml" stopProcessing="true" patternSyntax="Wildcard">
                    <!-- This rule works on and off. When it doesn't work, it returns a 404 (Not found) error -->
                    <match url="*" />
                    <conditions>
                        <add input="{REQUEST_URI}" pattern="/myFile.xml" />
                    </conditions>
                    <action type="Rewrite" url="/SiteDependentFiles/{HTTP_HOST}/new_myFile.xml"  appendQueryString="false"/>
                </rule>
                <rule name="Mask thisThingy.txt" stopProcessing="true" patternSyntax="Wildcard">
                    <!-- This rule never works and it returns a 500 (Internal Server) error -->
                    <match url="*" />
                    <conditions>
                        <add input="{REQUEST_URI}" pattern="/thisThingy.txt" />
                    </conditions>
                    <action type="Rewrite" url="/SiteDependentFiles/{HTTP_HOST}/new_thisThingy.txt"  appendQueryString="false"/>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

      

This is what I get in the "detailed report"

404.0 Error - Details

  • Module: IIS Web Core
  • Notification: MapRequestHandler
  • Handler: StaticFile
  • Error code: 0x80070002
  • Requested URL: http://mySiteName.com:80/myFile.xml
  • Physical Path: D: \ Hosting \ 123123123 \ html \ myFile.xml
  • Login Method: Anonymous
  • Login User: Anonymous

500.0 Error - Details

  • Module: ServerSideIncludeModule
  • Notification: ExecuteRequestHandler
  • Handler: SSI-html
  • Error code: 0x80070002
  • Requested URL: http://mySiteName.com:80/thisThingy.txt
  • Physical Path: D: \ Hosting \ 123123123 \ html \ thisThingy.txt
  • Login Method: Anonymous
  • Login User: Anonymous

Now, if you change {HTTP_HOST}

the string in the second rule only , both rules will run:

    <action type="Rewrite" url="/SiteDependentFiles/StaticFolderName/new_thisThingy.txt"  appendQueryString="false"/>

      

Note:

I also tried to use another option patternSyntax

, Redirect

instead of Rewrite

, stopProcessing="false"

instead of {HTTP_HOST}

, instead of {HTTP_HOST}

added <clear />

, but nothing changes. Same behavior.

Bypass

Always add a rule condition with {HTTP_HOST}

to be able to use it {SERVER_NAME}

as a variable for the rule action

    <system.webServer>
        <rewrite>
            <rules>
                <clear /> 
                <!--
                    ALWAYS ADD <add input="{HTTP_HOST}" pattern="*" /> TO BE 
                    ABLE TO USE {SERVER_NAME} MULTIPLE TIMES. (GODADDY ISSUE)
                -->
                <rule name="Mask myFile.xml" stopProcessing="true" patternSyntax="Wildcard">
                    <match url="*" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="*" />
                        <add input="{REQUEST_URI}" pattern="/myFile.xml" />
                    </conditions>
                    <action type="Rewrite" url="/SiteDependentFiles/{SERVER_NAME}/new_myFile.xml"  appendQueryString="false"/>
                </rule>
                <rule name="Mask thisThingy.txt" stopProcessing="true" patternSyntax="Wildcard">
                    <match url="*" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="*" />
                        <add input="{REQUEST_URI}" pattern="/thisThingy.txt" />
                    </conditions>
                    <action type="Rewrite" url="/SiteDependentFiles/{SERVER_NAME}/new_thisThingy.txt"  appendQueryString="false"/>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

      

Note:

  • I am using {HTTP_HOST}

    and {SERVER_NAME}

    , but using only {HTTP_HOST}

    may work. I cannot verify this right now.

thank

+3


source to share





All Articles