title: rewrite url rules to remove appearance of subdirectory in asp.net web.config file
body: <p>I have a domain that is hosted by discountasp.net (a standard .net web host). Call it <a href="http://example.com" rel="nofollow">http://example.com</a>.</p>
  
  <p>The domain hosts a default website, plus there are a couple separate web applications.</p>
  
  <p>The website was created in Wordpress, and it lives in a /wordpress subdirectory of the domain's root directory on the host.</p>
  
  <p>I want to make it so that there is no /wordpress in the URL the user sees in the browser. Previously, there was an index.html file in the root directory that would redirect requests for <a href="http://example.com/" rel="nofollow">http://example.com/</a> to <a href="http://example.com/wordpress/" rel="nofollow">http://example.com/wordpress/</a>. But that of course is just a redirect and leaves <a href="http://example.com/wordpress/" rel="nofollow">http://example.com/wordpress/</a> in the browser URL bar.</p>
  
  <p>I thought I could achieve what I wanted with URL rewrite rules in my Web.config file in the root directory. Below is the text of that file.</p>
  
  <blockquote>
  <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="wordpress redirect a"&gt;
                &lt;match url="wordpress/(.*)"/&gt;
                &lt;action type="Rewrite" url="{R:1}"/&gt;
            &lt;/rule&gt;
            &lt;rule name="wordpress redirect b"&gt;
                &lt;match url=".*"/&gt;
                &lt;conditions&gt;
                    &lt;add input="{REQUEST_URI}" pattern=".*nm.*" matchType="Pattern" negate="true" ignoreCase="false"/&gt;
                    &lt;add input="{REQUEST_URI}" pattern=".*survey.*" matchType="Pattern" negate="true" ignoreCase="false"/&gt;
                &lt;/conditions&gt;
                &lt;action type="Rewrite" url="wordpress/{R:0}"/&gt;
            &lt;/rule&gt;
        &lt;/rules&gt;
      &lt;/rewrite&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  </blockquote>
  
  <p>The logic of the file is:</p>
  
  <ul>
  <li><p>The first rule: if the url path (the part after the host:port/) starts with <code>wordpress/</code>, it removes the <code>wordpress/</code> and continues processing rules with just the part that came after the <code>wordpress/</code>.</p></li>
  <li><p>The second rule: for any url path that does not contains the special web application strings "nm" or "survey", put <code>wordpress/</code> in front on the path.</p></li>
  </ul>
  
  <p>This works, in the sense that if I put <a href="http://example.com/" rel="nofollow">http://example.com/</a> into the browser bar, it shows the website correctly, and also this rewriting does not interfere with the web application calls such as <a href="http://example.com/nm/" rel="nofollow">http://example.com/nm/</a>...</p>
  
  <p><strong>However, it still leaves the /wordpress in the URL the user sees (i.e., when I put <a href="http://example.com/" rel="nofollow">http://example.com/</a> in the browser bar, I end up with <a href="http://example.com/wordpress/" rel="nofollow">http://example.com/wordpress/</a> in the browser bar after whatever rewrite/redirect it does.</strong> It may be that I'm just misunderstanding what rewrite rules do. But my understanding (and what I was trying to achieve with these rules) was that any incoming URL (except my special web application URLs) that does not include <code>wordpress/</code> would be handled internally as if it did include <code>/wordpress</code>, but then returned to the client as the original URL not including <code>/wordpress</code>. So, not a redirect, just some internal fakery. And then the first rule is there because the links within the website would include <code>/wordpress</code>, and since I don't want to get <code>/wordpress/wordpress</code>, I need to strip it before adding it.</p>
  
  <p>But obviously I'm misunderstanding something.</p>
  
  <p>Another clue is that the second rule doesn't even seem to be doing its job when I use the url <a href="http://example.com/about/" rel="nofollow">http://example.com/about/</a>. The second rule should make this operate as if it were <a href="http://example.com/wordpress/about/" rel="nofollow">http://example.com/wordpress/about/</a>, but instead I get a 404 not found error. But if I put <a href="http://example.com/wordpress/about/" rel="nofollow">http://example.com/wordpress/about/</a> in the browser bar, it shows that web page correctly. So I'm confused.</p>