If your only goal is to achieve not ever seeing /frontend/web or /backend/web, even without using .htaccess rules, you could go for the following. Before procees make sure your directory structure would look like :
- yii2app/
- frontend/
- backend/
- common/
- .. other folders..
- admin/
- assets/
- css/
- index.php
- assets/
- css/
- index.php
Go to root directory of your Yii2 application and create index.php page like : yii2aap/index.php
then copy bellow code snippets and paste in your page and save it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); require(__DIR__ . '/vendor/autoload.php'); require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php'); require(__DIR__ . '/common/config/bootstrap.php'); require(__DIR__ . '/frontend/config/bootstrap.php'); $config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/common/config/main.php'), require(__DIR__ . '/common/config/main-local.php'), require(__DIR__ . '/frontend/config/main.php'), require(__DIR__ . '/frontend/config/main-local.php') ); $application = new yii\web\Application($config); $application->run(); |
Go to admin directory of your Yii2 application and create index.php page like : yii2aap/admin/index.php
then copy bellow code snippets and paste in your page and save it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); require(__DIR__ . '/../common/config/bootstrap.php'); require(__DIR__ . '/../backend/config/bootstrap.php'); $config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/../common/config/main.php'), require(__DIR__ . '/../common/config/main-local.php'), require(__DIR__ . '/../backend/config/main.php'), require(__DIR__ . '/../backend/config/main-local.php') ); $application = new yii\web\Application($config); $application->run(); |
After doing above step, then go to the browser and remove frontend and backend from your browser url.
Thank you for giving time on freewebmentor community. Please don’t forget to subscribe our newsletter or join us on Facebook to be the first to learn the next great thing from freewebmentor.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: remove backend frontend from url, Technology, Tip and tricks, Tutorials, Yii, yii2 framework