title: htaccess rewrites for two directories
body: <p>I am attempting to use rewrite rules for accessing two directories. I grabbed and tested a lot of code from online and other SO posts but what I ended up with still doesn't work properly. Here's what I'm trying to do:</p>
  
  <p>1) If page request is for /home, /test, /404, /etc, load the files from the /app directory and traverse like this: /home, /news/topics/post, /contact/, /blog/category/date/post</p>
  
  <p>2) If the page request is for /admin only, then load the files from the /admin directory and be able to traverse like so: /admin or /dashboard, /admin/page/edit, /admin/page/delete, /admin/page/create, /admin/section/delete/</p>
  
  <p>What is happening?
  If I go to /home or just /, works just fine! But if I got to /test, /contact, /admin, /etc I get a 404 file not found</p>
  
  <p>File structure (can be changed though):</p>
  
  <pre><code>/admin
   --dashboard.php
  
  /app
   --index.php
  
  .favicon.png
  .favicon.ico
  .htaccess
  </code></pre>
  
  <p>I'm starting to think that it might be better to just hard-code the rewrites like this instead:</p>
  
  <pre><code>RewriteRule ^home$ /atlas.php [NC,L]
  RewriteRule ^admin$ /admin/dashboard.php [NC,L]
  </code></pre>
  
  <p>...but I thought I'd see if the SO community could help before I throw in the towel on this one.</p>
  
  <p>Any suggestions?</p>
  
  <p>My current code:</p>
  
  <pre><code>Options -Indexes
  Options -MultiViews
  Options +FollowSymLinks
  
  
  # Set the default site page
  DirectoryIndex /app/index.php home
  
  
  # Rewrite Rules and Conditions
  &lt;IfModule mod_rewrite.c&gt;
  RewriteEngine on
  RewriteBase /
  
  # Remove www
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^(.*)$ http://%1/$1 [R=301,L,NC]
  
  
  # Assets are in /app
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)\.(gif|jpg|png|jpeg|css|js|svg|swf)$ /app/$1.$2 [L,NC]
  
  
  # First, check if request is to site pages, which is in /app/
  RewriteCond %{DOCUMENT_ROOT}/app%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}/app%{REQUEST_URI} -d
  RewriteRule ^(.*)$ /app/index.php?/$1 [NC,L]
  
  
  # Second, check if request is to /admin, which is in /admin/
  RewriteCond %{DOCUMENT_ROOT}/admin%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}/admin%{REQUEST_URI} -d
  RewriteRule ^(.*)$ /admin/dashboard.php?/$1 [NC,L]
  
  
  # Default to /app
  RewriteCond ${REQUEST_URI} !^/app/
  RewriteRule ^(\w+)$ /app/$1 [L]
  
  &lt;/IfModule&gt;
  </code></pre>