Yii Advanced Application Frontend & Backend Urls


I’ve been following Yii2 since quite some time and after Public Preview thought to give it a try. In particular I liked the advanced application structure and thought to move ahead with it.

However, while installing, realized that accessing frontend & backend is done via

http://example.com/frontend/web/ and http://example.com/backend/web/

Would it be possible to have them as

http://example.com/ (pointing to frontend) and http://example.com/backend/

It’s quite easily to do this by moving the contents of frontend/web to webroot and backend/web to webroot/backend.

You’ll also need to modify require() dirs inside index.php

Yet another way is to place all dirs under webroot and edit .htaccess so that webroot will be rewrited to subdir. Kinda tricky though.

Won’t moving frontend/web under webroot and backend/web under webroot/backend merge too application code?

It will mean I’m placing backend directory under frontend/web. right?

.htaccess based solution could be tricky to manage for sure.

Is it that the directory structure is decided to have two separate domain / sub-domains pointing to both the applications?

Yes, the idea is to have a subdomain for backend.

@samdark, Thank you. The query is resolved now.

Please close the thread.

Released a new application template yii2-app-practical to the community that does this automatically.

It’s not recommended to have source code under webroot. You need to add a warning about securing it via webserver config.

Not sure I understood. Which source code (can you elaborate)?

Only the index.php will move to webroot (along with the runtime assets folder from the frontend/web). All other structure remain exactly the same as the yii2-advanced app (the same security should hold good IMO). Its only config file locations change.

If you look at the yii2-app-practical directory structure - its exactly same as yii2-app-advanced except that it does the following:


[*]moves frontend/web/index.php, favicon, and robots.txt to root.

[*]moves frontend/web/assets to root.

[*]deletes frontend/web folder

[*]carefully changes index.php configuration locations to point to the new relative vendor, common, and frontend paths.


And voila… you can now access frontend from the approot. B)

Why not using URL rewrite similar to ZF2 where module application is default even if you don’t mention it in the URL. I’m just asking i don’t have any idea how it’s handled in YII2 because i didn’t have enough time to analyze it.

Hello there,

You can view this link that it’s very useful:


Good luck.

which file is config to those url links?


Creating links from backend to frontend

return [

'components' => [

    'urlManager' => [

        // here is your normal backend url manager config


    'urlManagerFrontend' => [

        // here is your frontend URL manager config





How to use across subdomains? with advanced application, I tried this way


    'session' => [

        'savePath' => '\mypath\common\session',

        'cookieParams' => [

            'path' => '/',

            'domain' => '.mydomain.com',



    'user' => [

        'identityClass' => 'common\models\User',

        'enableAutoLogin' => true,

        'identityCookie' => [

            'name' => '_mydomain',

            'domain' => '.mydomain.com',

            'path' => '/',



This example for





All applications, need get user sessions/cookies, etc.

Any idea?