Create. htaccess file in root folder, i.e advanced/.htaccess
and write below code.
options +followsymlinksrewriteengine on# deal with admin Firstrewritecond%{ Request_uri} ^/(Admin) <------rewriterule ^admin/assets/(. *) $ backend/web/assets/$1 [L]rewriterule ^admin/css/(. * ) $ backend/web/css/$1 [L]rewritecond%{request_uri}!^/backend/web/(ASSETS|CSS)/<------Rewritecond%{REQUEST_URI } ^/(Admin) <------rewriterule ^.*$ backend/web/index.php [L]rewritecond%{request_uri} ^/(ASSETS|CSS) <------ Rewriterule ^assets/(. *) $ frontend/web/assets/$1 [L]rewriterule ^css/(. *) $ frontend/web/css/$1 [L]RewriteCond%{ Request_uri}!^/(Frontend|backend)/web/(ASSETS|CSS)/<------Rewritecond%{request_uri}!index.phprewritecond%{ Request_filename}!-f [Or]rewritecond%{request_filename}!-drewriterule ^.*$ frontend/web/index.php
Note: If you is trying in local server then replace^/
with^/project_name/
where you see arrow sign. Remove those arrow sign<------
After Setup was done .
now create a components/request.php
file in common directory and write below code in the this file.
namespace Common\components;class Request extends \yii\web\request {public $web; public $adminUrl; Public Function Getbaseurl () { return str_replace ($this->web, "", Parent::getbaseurl ()). $this->adminurl; } /* If you don't have this function, the admin site would 404 If you leave off the trailing slash. e.g.: wouldn ' t work: site.com/admin would work: site.com/admin/ Using This function, both would work. */Public function Resolvepathinfo () { if ($this->geturl () = = = $this->adminurl) { return ""; } else{ return Parent::resolvepathinfo ();}}
installing component. Write below code infrontend/config/main.php
andbackend/config/main.php
files respectively.
Frontend, under Components array ' request ' =>[ ' class ' = ' common\components\request ', ' web ' = '/ Frontend/web '], ' urlmanager ' = = [ ' enableprettyurl ' = True, ' showscriptname ' and false,],//backend, Under Components array ' request ' =>[ ' class ' = ' common\components\request ', ' web ' = '/backend/web ', ' adminurl ' = '/admin '], ' urlmanager ' and ' = ' enableprettyurl ' + true, ' showscriptname ' = False,],
Create. htaccess file in web directory
Rewriteengine on Rewritecond%{request_filename}!-f rewritecond%{request_filename}!-d RewriteRule ^ (. *) $/index.php?/ $ [L]
Note:make sure you have the enabled your mod rewrite in Apache
Thats it! You can try your project with
Www.project.com/admin, www.project.com
In local server
Localhost/project_name/admin, Localhost/project_name
above is the premium version of advanced configuration method, the basic version does not need this configuration.
The biggest difference between advanced and basic is that the two directories, the backend directory and the frontend directory, are separated from the front and rear tables, which are actually two yii applications that are common to basic, such as the model part, which are stored in the common directory. This advanced application is suitable for more complex and large projects to completely separate the front-end business logic so access to the front and back of the platform is equivalent to access to two different applications
So when configuring the Vhost Webroot directory, assume that the domain name is www.xxx.com so www.xxx.com points to the foreground directory/frontend/web/
Configure level two domain name root.xxx.com point to/backend/web/
For the package that just touches Yii2, start with basic
Yii2 How to hide Frontend/web and Backend/web