Yii2 htaccess - How to hide frontend/web and backend/web COMPLETELY

I think I am pretty close. I have the htaccess redirecting to the website (frontend/web) and the /admin path (backend/web). The site appears fine, CSS files loading, etc.

If you go to: localhost/yii2app/ - it loads the homepage, and doesn’t redirect in the address bar, but the page shows frontend/web in all the URLs.

if you go to: localhost/yii2app/admin - it loads the backend login page, however it immediately redirects to /backend/web/site/login in the address bar (ugly).

Problem: The frontend/backend paths are showing in the URLs (address bar, and links on the page).

What I need: I want the whole site to operate without showing frontend/backend links. The project’s root should pull (invisibly) from the frontend/web without showing it… So localhost/yii2app/ runs my whole frontend, and localhost/yii2app/admin/ runs my whole backend.

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.

.htaccess file in /yii2app dir:

Options +FollowSymlinks

RewriteEngine On

deal with admin first

RewriteCond %{REQUEST_URI} @^/yii2app /(admin)

RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]

RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]

RewriteCond %{REQUEST_URI} !@^/yii2app/backend/web/(assets|css)/

RewriteCond %{REQUEST_URI} @^/yii2app/(admin)

RewriteRule ^.*$ backend/web/index.php [L]

RewriteCond %{REQUEST_URI} @^/yii2app/frontend/web/(assets|css)

RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]

RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]

RewriteCond %{REQUEST_URI} !@^/yii2app/(frontend|backend)/web/(assets|css)/

RewriteCond %{REQUEST_URI} !index.php

RewriteCond %{REQUEST_FILENAME} !-f [OR]

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^.*$ frontend/web/index.php

Now in frontend and backend web directories, they both have the same .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /index.php?/$1 [L]

backend\config\main.php

<?php

$params = array_merge(

require(__DIR__ . '/&#46;&#46;/&#46;&#46;/common/config/params.php'),


require(__DIR__ . '/&#46;&#46;/&#46;&#46;/common/config/params-local.php'),


require(__DIR__ . '/params.php'),


require(__DIR__ . '/params-local.php')

);

return [

'id' =&gt; 'app-backend',


'basePath' =&gt; dirname(__DIR__),


'controllerNamespace' =&gt; 'backend&#092;controllers',


'bootstrap' =&gt; ['log'],


'modules' =&gt; [],


'components' =&gt; [


    'request'=&gt;[


        'class' =&gt; 'common&#092;components&#092;Request',


        'web'=&gt; '/backend/web',


    ],


    'urlManager' =&gt; [


        'enablePrettyUrl' =&gt; true,


        'showScriptName' =&gt; false,


    ],


    'user' =&gt; [


        'identityClass' =&gt; 'common&#092;models&#092;User',


        'enableAutoLogin' =&gt; true,


    ],


    'log' =&gt; [


        'traceLevel' =&gt; YII_DEBUG ? 3 : 0,


        'targets' =&gt; [


            [


                'class' =&gt; 'yii&#092;log&#092;FileTarget',


                'levels' =&gt; ['error', 'warning'],


            ],


        ],


    ],


    'errorHandler' =&gt; [


        'errorAction' =&gt; 'site/error',


    ],


],


'params' =&gt; &#036;params,

];

frontend\config\main.php

<?php

$params = array_merge(

require(__DIR__ . '/&#46;&#46;/&#46;&#46;/common/config/params.php'),


require(__DIR__ . '/&#46;&#46;/&#46;&#46;/common/config/params-local.php'),


require(__DIR__ . '/params.php'),


require(__DIR__ . '/params-local.php')

);

return [

'id' =&gt; 'app-frontend',


'basePath' =&gt; dirname(__DIR__),


'bootstrap' =&gt; ['log'],


'controllerNamespace' =&gt; 'frontend&#092;controllers',


'components' =&gt; [





    'request'=&gt;[


        'class' =&gt; 'common&#092;components&#092;Request',


        'web'=&gt; '/frontend/web'


    ],


    'urlManager' =&gt; [


        'enablePrettyUrl' =&gt; true,


        'showScriptName' =&gt; false,


    ],


    'user' =&gt; [


        'identityClass' =&gt; 'common&#092;models&#092;User',


        'enableAutoLogin' =&gt; true,


    ],


    'log' =&gt; [


        'traceLevel' =&gt; YII_DEBUG ? 3 : 0,


        'targets' =&gt; [


            [


                'class' =&gt; 'yii&#092;log&#092;FileTarget',


                'levels' =&gt; ['error', 'warning'],


            ],


        ],


    ],


    'errorHandler' =&gt; [


        'errorAction' =&gt; 'site/error',


    ],


    


],


'params' =&gt; &#036;params,

];