title: Yii2 htaccess - How to hide frontend/web and backend/web COMPLETELY
body: <p>I think I am pretty close. I have the htaccess redirecting to the website (frontend/web) and the <code>/admin</code> path (<code>backend/web</code>). The site appears fine, CSS files loading, etc.</p>
  
  <p>If you go to: <a href="http://localhost/yii2app/">http://localhost/yii2app/</a>  - it loads the homepage, and doesn't redirect in the address bar, but the page shows frontend/web in all the URLs.</p>
  
  <p>if you go to: <a href="http://localhost/yii2app/admin">http://localhost/yii2app/admin</a>  - it loads the backend login page, however it immediately redirects to /backend/web/site/login in the address bar (ugly).</p>
  
  <p>Problem: The <code>frontend/backend</code> paths are showing in the URLs (address bar, and links on the page).</p>
  
  <p>What I need: I want the whole site to operate without showing frontend/backend links. The project's root should pull (invisibly) from the <code>frontend/web</code> without showing it.. So <a href="http://localhost/yii2app/">http://localhost/yii2app/</a> runs my whole frontend, and <a href="http://localhost/yii2app/admin/">http://localhost/yii2app/admin/</a> runs my whole backend.</p>
  
  <p>Why? I feel this setup would be pretty solid and elegant when live on a server. I want to be able to push my project folder live to a site and it work just fine without having to have hacks to handle local vs server.</p>
  
  <p><code>.htaccess</code> file in <code>/yii2app</code> dir:</p>
  
  <pre><code>Options -Indexes
  RewriteEngine on
  
  &lt;IfModule mod_rewrite.c&gt;
      RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
      RewriteCond %{REQUEST_URI} admin
      RewriteRule .* backend/web/index.php [L]
  
      RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css)/
      RewriteCond %{REQUEST_URI} !admin
      RewriteRule .* frontend/web/index.php [L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>Now in frontend and backend web directories, they both have the same <code>.htaccess</code>:</p>
  
  <pre><code>RewriteEngine on
  
  # if a directory or a file exists, use the request directly
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  
  # otherwise forward the request to index.php
  RewriteRule . index.php
  </code></pre>
  
  <p>I do not want to see <code>/frontend/web</code> or <code>/backend/web</code> ever :)</p>
  
  <p>I tried to play with the RewriteRule in the root's htaccess to add <code>/admin</code> to the URL, but it kept telling me <code>/admin</code> does not exist. I <em>KNOW</em> it does not exist, and I don't want it to exist. I want it to be a relative path.. ie: /admin == /backend/web.</p>
  
  <p>Worded another way. I way everything in the project's root (<a href="http://localhost/yii2app/">http://localhost/yii2app/</a>) to load <code>frontend/web</code>, but without showing it. Also, <a href="http://localhost/yii2app/admin">http://localhost/yii2app/admin</a> to load <code>backend/web</code> and just showing <a href="http://localhost/yii2app/admin">http://localhost/yii2app/admin</a>. Obviously they would have their respective <code>controller/action</code> attached to them. So admin could look like <a href="http://localhost/yii2app/admin/site/login">http://localhost/yii2app/admin/site/login</a></p>
  
  <p>NOTE: I have not played with any of the files. This is a stock yii2 advanced setup, using composer, and following the docs. The only thing I have played with so far are the htaccess files mentioned.</p>
  
  <p>Thank you!</p>