您好,欢迎来到保捱科技网。
搜索
您的当前位置:首页配置yii程序支持虚拟主机的方法

配置yii程序支持虚拟主机的方法

来源:保捱科技网


一、将frontend/web/的程序复制到根目录下

二、将index.php的程序做如下修改:

<?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 = yiihelpersArrayHelper::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 yiiwebApplication($config))->run();

三、将frontend下的目录web目录删除

四、在将api端实现为:www.***.com/api/web/site/login的模式时,发现实现不了,好像是调用不到index.php及控制器也调用不了。于是做了各种猜想,一步一步排除法排查问题,排除法是在不知底层的情况下发现问题和解决问题的好办法。

与之对应的就是读底层代码,但这样虽然能解决问题,速度会更慢。最后发现可以将.haccess的代码改为以下形式实现了隐藏index.php及实现伪静态:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /api/web/index.php [L]
</IfModule>

在调试api的过程中发现www.***.com/api/web/articles在浏览器里面查看代码时,无法显示xml数据,或者是下载.json的提示,后来发现是选择了360浏览器的兼容模式,改为极速模式就好了。在postman里面测试数据时是成功的。

推荐教程:YII教程

Copyright © 2019- baoaiwan.cn 版权所有 赣ICP备2024042794号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务