网站首页 > 开源技术 正文
用Yii2高级应用程序模板搭建的系统,根目录设置为wwwroot,访问路径是这样的,前台访问路径:http://localhost/frontend/web, 后台访问路径:http://localhost/backend/web, 这样的访问不是很方便。那么怎么样才能修改为 http://localhost 和 http://localhost/admin 这样的访问路径呢?
首先我们先看下Yii2高级应用程序模板的目录结构,如下图所示:
第一步:需要把网址的运行目录指向 frontend/web 文件。这样就能 http://localhost 访问到前台。下面步骤就解决怎么访问后台。
第二步:在frontend/web目录下面建一个文件夹admin。把原本在backend/web下面的文件迁移到admin下面。
第三步:修改frontend/web/admin 目录下面的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__ . '/../../../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'
);
(new yii\web\Application($config))->run();
第四步:浏览器输入http://localhost/admin 看是否能正常访问到后台。Nginx服务器需要配置伪静态:
location / {
#Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
#If you want a single domain name at the front and back ends
location /admin {
try_files $uri $uri/ /admin/index.php$is_args$args;
}
具体案例可以参考:
http://test.shopwind.net
http://test.shopwind.net/admin
案例源码下载:https://gitee.com/shopwind/yii2-shopwind
猜你喜欢
- 2024-09-11 少年歌行。第2部。萧崇登基后……
- 2024-09-11 少年歌行2:司空千落怀孕,萧瑟居然要娶别人为妻
- 2024-09-11 YII框架学习(新手)NO.2(yii框架设计模式)
- 2024-09-11 yii安装与使用详解(easy_install安装)
- 2024-09-11 小编教你 YII2框架模块如何绑定二级域名
- 2024-09-11 一款基于Yii2+Vue2.0+uniapp的开源商城
- 2024-09-11 Yii2开发中js冲突 如何禁用自带的 yii、jquery 和 bootstrap
- 2024-09-11 一款基于Yii2开发的免费商城系统(开发一款游戏的步骤)
- 2024-09-11 Yii2连接pgsql,设置默认schema(sqlplus默认连库)
- 2024-09-11 php生命周期、Laravel生命周期、Yii2生命周期、ThinkPHP生命周期
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- jdk (81)
- putty (66)
- rufus (78)
- 内网穿透 (89)
- okhttp (70)
- powertoys (74)
- windowsterminal (81)
- netcat (65)
- ghostscript (65)
- veracrypt (65)
- asp.netcore (70)
- wrk (67)
- aspose.words (80)
- itk (80)
- ajaxfileupload.js (66)
- sqlhelper (67)
- express.js (67)
- phpmailer (67)
- xjar (70)
- redisclient (78)
- wakeonlan (66)
- tinygo (85)
- startbbs (72)
- webftp (82)
- vsvim (79)
本文暂时没有评论,来添加一个吧(●'◡'●)