title: Codeigniter URL rewrite in Web.config not working in sub directory on Windows IIS server
body: <p>I have developed my website using PHP Framework - Codeigniter 2. There is a front-end and a back-end to this website. </p>
  
  <p>For the back-end i have created a directory called <strong>webadmin</strong> in the root directory of my website.</p>
  
  <p>This website was previously hosted on LINUX OS using APACHE server, but recently we have moved on to dedicated WINDOWS OS server using IIS server.</p>
  
  <p>Previously on  LINUX I was using 2 htaccess files one in the root and other in my sub-directory. It was working perfectly in both the cases.</p>
  
  <p>Now due to IIS server I had to import all my settings to IIS Web.config file. Resulting web.config works perfectly for my front-end with the rewrite rule for index.php, but doesn't work in my sub-directory that is <strong><a href="http://www.somedomain.com/webadmin" rel="nofollow">http://www.somedomain.com/webadmin</a></strong> . </p>
  
  <p>I have used the following web.config file in my root: -</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="Clean URL" stopProcessing="true"&gt;
                  &lt;match url="^(.*)$" /&gt;
                  &lt;conditions&gt;
                      &lt;add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /&gt;
                      &lt;add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /&gt;
                  &lt;/conditions&gt;
                  &lt;action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" /&gt;
              &lt;/rule&gt;
          &lt;/rules&gt;
      &lt;/rewrite&gt;
          &lt;defaultDocument&gt;
              &lt;files&gt;
                  &lt;clear /&gt;
                  &lt;add value="Index.php" /&gt;
                  &lt;add value="Index.html" /&gt;
                  &lt;add value="Index.htm" /&gt;
                  &lt;add value="Index.cfm" /&gt;
                  &lt;add value="Index.shtml" /&gt;
                  &lt;add value="Index.shtm" /&gt;
                  &lt;add value="Index.stm" /&gt;
                  &lt;add value="Index.php3" /&gt;
                  &lt;add value="Index.asp" /&gt;
                  &lt;add value="Index.aspx" /&gt;
                  &lt;add value="Default.htm" /&gt;
                  &lt;add value="Default.asp" /&gt;
                  &lt;add value="Default.aspx" /&gt;
              &lt;/files&gt;
          &lt;/defaultDocument&gt;
          &lt;httpErrors errorMode="Detailed" /&gt;
      &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Next is the web.config file from my sub-directory which is not working and giving me 404 error.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
      &lt;system.webServer&gt;
          &lt;security&gt;
              &lt;requestFiltering allowDoubleEscaping="true" /&gt;
          &lt;/security&gt;
          &lt;rewrite&gt;
              &lt;rules&gt;
                  &lt;rule name="YOURLS" stopProcessing="true"&gt;
                      &lt;match url="^webadmin/(.*)$" ignoreCase="false" /&gt;
                      &lt;conditions&gt;
                          &lt;add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /&gt;
                          &lt;add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /&gt;
                      &lt;/conditions&gt;
                      &lt;action type="Rewrite" url="/webadmin/index.php/{R:1}" appendQueryString="true" /&gt;
                  &lt;/rule&gt;
              &lt;/rules&gt;
          &lt;/rewrite&gt;
      &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>