title: Can't use {HTTP_HOST} for multiple rewrite rules in web.config file with GoDaddy Hosting - IIS 7.0
body: <p>I came across a weird issue while creating a few rewrite rules for my website which is hosted by GoDaddy. I'm able to create one rewrite rule using the <code>{HTTP_HOST}</code> or <code>{SERVER_NAME}</code> variables, but at the time of adding a second rule, it looks like the <code>{HTTP_HOST}</code>/<code>{SERVER_NAME}</code> doesn't return a value (I guess), so my code fails.</p>
  
  <p>After a small mistake, I found a work around to the issue (which I will add at the bottom). I'm asking this question because I would like to:</p>
  
  <ul>
  <li>Understand the reason of this behavior </li>
  <li>Know if this is happening to    someone else</li>
  <li>Find out if my approach is wrong or if I'm missing something for
  it to work </li>
  </ul>
  
  <p>Due to this issue, I decided to clear my whole web.config file for testing purposes and have only the rewrite rules. I tried multiple changes, but I can't recall all of them at this time, so I will add as much as I remember. </p>
  
  <h1>Issue</h1>
  
  <p>This code works</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;system.webServer&gt;
          &lt;rewrite&gt;
              &lt;rules&gt;
                  &lt;rule name="Mask myFile.xml" stopProcessing="true" patternSyntax="Wildcard"&gt;
                      &lt;!-- This rule always --&gt;
                      &lt;match url="*" /&gt;
                      &lt;conditions&gt;
                          &lt;add input="{REQUEST_URI}" pattern="/myFile.xml" /&gt;
                      &lt;/conditions&gt;
                      &lt;action type="Rewrite" url="/SiteDependentFiles/{HTTP_HOST}/new_myFile.xml"  appendQueryString="false"/&gt;
                  &lt;/rule&gt;
              &lt;/rules&gt;
          &lt;/rewrite&gt;
      &lt;/system.webServer&gt;
  </code></pre>
  
  <p>This code doesn't (see notes inside code)</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;system.webServer&gt;
          &lt;rewrite&gt;
              &lt;rules&gt;
                  &lt;rule name="Mask myFile.xml" stopProcessing="true" patternSyntax="Wildcard"&gt;
                      &lt;!-- This rule works on and off. When it doesn't work, it returns a 404 (Not found) error --&gt;
                      &lt;match url="*" /&gt;
                      &lt;conditions&gt;
                          &lt;add input="{REQUEST_URI}" pattern="/myFile.xml" /&gt;
                      &lt;/conditions&gt;
                      &lt;action type="Rewrite" url="/SiteDependentFiles/{HTTP_HOST}/new_myFile.xml"  appendQueryString="false"/&gt;
                  &lt;/rule&gt;
                  &lt;rule name="Mask thisThingy.txt" stopProcessing="true" patternSyntax="Wildcard"&gt;
                      &lt;!-- This rule never works and it returns a 500 (Internal Server) error --&gt;
                      &lt;match url="*" /&gt;
                      &lt;conditions&gt;
                          &lt;add input="{REQUEST_URI}" pattern="/thisThingy.txt" /&gt;
                      &lt;/conditions&gt;
                      &lt;action type="Rewrite" url="/SiteDependentFiles/{HTTP_HOST}/new_thisThingy.txt"  appendQueryString="false"/&gt;
                  &lt;/rule&gt;
              &lt;/rules&gt;
          &lt;/rewrite&gt;
      &lt;/system.webServer&gt;
  </code></pre>
  
  <p>This is what I get in the "detail report"</p>
  
  <p>404.0 Error - Details</p>
  
  <ul>
  <li><strong>Module:</strong> IIS Web Core</li>
  <li><strong>Notification:</strong> MapRequestHandler</li>
  <li><strong>Handler:</strong> StaticFile</li>
  <li><strong>Error Code:</strong> 0x80070002</li>
  <li><strong>Requested URL:</strong> <a href="http://mySiteName.com:80/myFile.xml" rel="nofollow">http://mySiteName.com:80/myFile.xml</a></li>
  <li><strong>Physical Path:</strong> D:\Hosting\123123123\html\myFile.xml</li>
  <li><strong>Logon Method:</strong> Anonymous</li>
  <li><strong>Logon User:</strong> Anonymous</li>
  </ul>
  
  <p>500.0 Error - Details</p>
  
  <ul>
  <li><strong>Module:</strong> ServerSideIncludeModule</li>
  <li><strong>Notification:</strong> ExecuteRequestHandler</li>
  <li><strong>Handler:</strong> SSI-html</li>
  <li><strong>Error Code:</strong> 0x80070002</li>
  <li><strong>Requested URL:</strong> <a href="http://mySiteName.com:80/thisThingy.txt" rel="nofollow">http://mySiteName.com:80/thisThingy.txt</a></li>
  <li><strong>Physical Path:</strong> D:\Hosting\123123123\html\thisThingy.txt</li>
  <li><strong>Logon Method:</strong> Anonymous</li>
  <li><strong>Logon User:</strong> Anonymous</li>
  </ul>
  
  <p>Now, if change <code>{HTTP_HOST}</code> for a string in the second rule <strong>only</strong>, both rules start working:</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;action type="Rewrite" url="/SiteDependentFiles/StaticFolderName/new_thisThingy.txt"  appendQueryString="false"/&gt;
  </code></pre>
  
  <h3>Please note:</h3>
  
  <p>I also tried using a different <code>patternSyntax</code> option, <code>Redirect</code> instead of <code>Rewrite</code>, <code>stopProcessing="false"</code>, used <code>{SERVER_NAME}</code> instead of <code>{HTTP_HOST}</code>, added <code>&lt;clear /&gt;</code> before first rule, but nothing changes. Same behavior.</p>
  
  <h1>Workaround</h1>
  
  <p>Always add a rule <em>condition</em> with <code>{HTTP_HOST}</code> to be able to use <code>{SERVER_NAME}</code> as variable for rule's <em>action</em></p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;system.webServer&gt;
          &lt;rewrite&gt;
              &lt;rules&gt;
                  &lt;clear /&gt; 
                  &lt;!--
                      ALWAYS ADD &lt;add input="{HTTP_HOST}" pattern="*" /&gt; TO BE 
                      ABLE TO USE {SERVER_NAME} MULTIPLE TIMES. (GODADDY ISSUE)
                  --&gt;
                  &lt;rule name="Mask myFile.xml" stopProcessing="true" patternSyntax="Wildcard"&gt;
                      &lt;match url="*" /&gt;
                      &lt;conditions&gt;
                          &lt;add input="{HTTP_HOST}" pattern="*" /&gt;
                          &lt;add input="{REQUEST_URI}" pattern="/myFile.xml" /&gt;
                      &lt;/conditions&gt;
                      &lt;action type="Rewrite" url="/SiteDependentFiles/{SERVER_NAME}/new_myFile.xml"  appendQueryString="false"/&gt;
                  &lt;/rule&gt;
                  &lt;rule name="Mask thisThingy.txt" stopProcessing="true" patternSyntax="Wildcard"&gt;
                      &lt;match url="*" /&gt;
                      &lt;conditions&gt;
                          &lt;add input="{HTTP_HOST}" pattern="*" /&gt;
                          &lt;add input="{REQUEST_URI}" pattern="/thisThingy.txt" /&gt;
                      &lt;/conditions&gt;
                      &lt;action type="Rewrite" url="/SiteDependentFiles/{SERVER_NAME}/new_thisThingy.txt"  appendQueryString="false"/&gt;
                  &lt;/rule&gt;
              &lt;/rules&gt;
          &lt;/rewrite&gt;
      &lt;/system.webServer&gt;
  </code></pre>
  
  <h3>Please note:</h3>
  
  <ul>
  <li>I'm using <code>{HTTP_HOST}</code> and <code>{SERVER_NAME}</code>, but using only <code>{HTTP_HOST}</code>could work. I can't test this right now.</li>
  </ul>
  
  <h1>Thank you</h1>