Home  >  Article  >  PHP Framework  >  How to configure the yii program to support virtual hosts

How to configure the yii program to support virtual hosts

王林
王林Original
2019-11-08 17:02:362529browse

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(&#39;YII_DEBUG&#39;) or define(&#39;YII_DEBUG&#39;, true);
defined(&#39;YII_ENV&#39;) or define(&#39;YII_ENV&#39;, &#39;dev&#39;);
 
require __DIR__ . &#39;/vendor/autoload.php&#39;;
require __DIR__ . &#39;/vendor/yiisoft/yii2/Yii.php&#39;;
require __DIR__ . &#39;/common/config/bootstrap.php&#39;;
require __DIR__ . &#39;/frontend/config/bootstrap.php&#39;;
 
$config = yii\helpers\ArrayHelper::merge(
    require __DIR__ . &#39;/common/config/main.php&#39;,
    require __DIR__ . &#39;/common/config/main-local.php&#39;,
    require __DIR__ . &#39;/frontend/config/main.php&#39;,
    require __DIR__ . &#39;/frontend/config/main-local.php&#39;
);
 
(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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn