title: Blocking invalid URL and redirect to homepage in IIS
body: <p>Currently I am using the web hosting service provided by another company. It uses IIS 7/IIS 8 and allows customers to modify <code>web.config</code> according to their needs.</p>
  
  <p>Suppose I have set up two valid URL:</p>
  
  <ol>
  <li><a href="http://www.example.com" rel="nofollow">http://www.example.com</a></li>
  <li><a href="http://dev.example.com" rel="nofollow">http://dev.example.com</a></li>
  </ol>
  
  <p>Now, when I try to access <code>http://abc.example.com</code>, <code>HTTP Error 403.14 - Forbidden</code> is returned; and if I then try to access <code>http://www.example.com/abc</code>, <code>HTTP Error 404.0 - Not Found</code> is returned.</p>
  
  <p>How can I configure <code>web.config</code> such that users will be redirected to <code>http://www.example.com</code> when they are trying to access an invalid URL?</p>
  
  <p>I have tried to use the snippet provided by the company but without success:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
      &lt;system.webServer&gt;
          &lt;rewrite&gt;
              &lt;rules&gt;
                  &lt;rule name="Canonical Host Name" stopProcessing="true"&gt;
                    &lt;match url="(.*)" /&gt;
                    &lt;conditions&gt;
                      &lt;add input="{HTTP_HOST}" pattern="^example\.com$" /&gt;
                    &lt;/conditions&gt;
                    &lt;action type="Redirect" url="http://www.example.com/{R:1}" redirectType="Permanent" /&gt;
                  &lt;/rule&gt;
               &lt;/rules&gt;
          &lt;/rewrite&gt;
      &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>