title: url rewriting everything to index.php except few is not working for a saas application
body: <p>I am using this code in my htaccess file to redirect all requests to index.php and it works.</p>
  <pre><code>RewriteEngine On
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  
  RewriteRule ^(.*)$ index.php [L,QSA]
  </code></pre>
  <p>Now, I am trying to redirect few requests to another file <code>public.php</code> (i..e load everthing via index.php if user is logged in, otherwise load files via public.php - that's the idea)</p>
  <p>I have tried several methods which works for others but none of them seems to be working for me., I have no idea why.</p>
  <p>the application structure is</p>
  <pre><code>[FOLDER]
  app
  www
  static
  .htaccess
  </code></pre>
  <p>And this is the .htaccess used in the root folder</p>
  <pre><code>RewriteCond %{HTTP_HOST} ^(www.)?website.com
  RewriteRule ^(.*)$ www/index.php?$1 [L,QSA]
  
  
  RewriteCond %{HTTP_HOST} ^(static.)?website.com
  RewriteRule ^(.*)$ static/index.php?$1 [L,QSA]
  
  
  RewriteCond %{HTTP_HOST} ^([^.]+)\.website\.com$ [NC] 
  RewriteRule ^(.*)$ app/index.php?$1 [L,QSA]
  </code></pre>
  <p>By default if the subdomain is <code>www</code> or <code>static</code> files are loaded from <code>www</code> and <code>static</code> folders respectively. If the url is accessed via some other subdomain then the files are loaded from <code>app</code> directory.</p>
  <h1>The codes i tried are</h1>
  <pre><code>RewriteEngine On
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  
  RewriteRule ^public$ public.php [L,QSA]
  RewriteRule ^(.*)$ index.php [L,QSA]
  </code></pre>
  <p>interchanged these two lines as well as tried with removing L, QSA</p>
  <p>And many others.., As many i could find on Google + Stackoverflow., But none of them worked, <code>I guess its not working due to how i have coded the .htaccess file in the root directory</code>.</p>
  <h2>If you guys can find any obvious problems with this htaccess codes please let me know how to fix it, No matter how much i try to learn htaccess i always suck at it, If you know of any good tutorial related to this please post its link as well.., I already Googled and read many articles on it already.</h2>