Home > Article > PHP Framework > How to configure the yii program to support virtual hosts
1. Copy the program of frontend/web/ to the root directory
2. Modify the program of index.php as follows:
<?php 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' ); (new yii\web\Application($config))->run();
3. Delete the directory web directory under frontend
4. When implementing the api end as: www.***.com/api/web/site/login mode, it was found that it could not be implemented, as if Index.php and the controller cannot be called, nor can they be called. So I made various conjectures and used the step-by-step elimination method to troubleshoot the problem. The elimination method is a good way to find and solve problems without knowing the underlying issues.
The corresponding solution is to read the underlying code, but although this can solve the problem, the speed will be slower. Finally, I found that the .haccess code can be changed to the following form to hide index.php and achieve pseudo-static:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /api/web/index.php [L] </IfModule>
During the process of debugging the api, I found www.***.com/api/web/articles When viewing the code in the browser, the xml data cannot be displayed, or there is a prompt to download .json. Later I found out that the compatibility mode of the 360 browser was selected, and it was just fine to change it to the speed mode. It was successful when testing the data in postman.
Recommended tutorial: YII tutorial
The above is the detailed content of How to configure the yii program to support virtual hosts. For more information, please follow other related articles on the PHP Chinese website!