Yii 是一个高性能,基于组件的 PHP 框架,用于快速开发现代 Web 应用程序。名字 Yii (读作 `易`)在中文里有 “极致简单与不断演变” 两重含义,也可看作 **Yes It Is**! 的缩写。
Create .htaccess file in root folder, i.e advanced/.htaccess and write below code.
Options +FollowSymlinks RewriteEngine On # deal with admin first RewriteCond %{REQUEST_URI} ^/(admin) <------ RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L] RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L] RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/ <------ RewriteCond %{REQUEST_URI} ^/(admin) <------ RewriteRule ^.*$ backend/web/index.php [L] RewriteCond %{REQUEST_URI} ^/(assets|css) <------ RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L] RewriteRule ^css/(.*)$ frontend/web/css/$1 [L] RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css)/ <------ RewriteCond %{REQUEST_URI} !index.php RewriteCond %{REQUEST_FILENAME} !-f [OR] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ frontend/web/index.php
Note : if you are trying in local server then replace ^/ with ^/project_name/ where you see arrow sign. Remove those arrow sign <------ after setup is done.
Now create a components/Request.php file in common directory and write below code in this file.
namespace common\components; class Request extends \yii\web\Request { public $web; public $adminUrl; public function getBaseUrl(){ return str_replace($this->web, "", parent::getBaseUrl()) . $this->adminUrl; } /* If you don't have this function, the admin site will 404 if you leave off the trailing slash. E.g.: Wouldn't work: site.com/admin Would work: site.com/admin/ Using this function, both will work. */ public function resolvePathInfo(){ if($this->getUrl() === $this->adminUrl){ return ""; }else{ return parent::resolvePathInfo(); } } }
Installing component. Write below code in frontend/config/main.php and backend/config/main.phpfiles respectively.
//frontend, under components array 'request'=>[ 'class' => 'common\components\Request', 'web'=> '/frontend/web' ], 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, ], // backend, under components array 'request'=>[ 'class' => 'common\components\Request', 'web'=> '/backend/web', 'adminUrl' => '/admin' ], 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, ],
create .htaccess file in web directory
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php"htmlcode">www.project.com/admin, www.project.comin local server
localhost/project_name/admin, localhost/project_name以上是高级版的Advanced配置方法,基础版的不需要这样配置。
Advanced和 basic 最大的区别就是分离了前后台 分别是 backend目录和frontend目录 这两个目录实际相对于 basic 来说其实就是两个Yii应用 他们公用的比如Model部分都存放在Common目录 这种高级应用适用于比较复杂大型的项目用于彻底分离开前后台业务逻辑 因此访问前后台就相当于访问两个不同的应用
因此在配置Vhost webroot 目录的时候 假设域名为 www.xxx.com 那么 www.xxx.com指向前台目录 /frontend/web/
配置二级域名root.xxx.com 指向/backend/web/
以上所述是小编给大家分享的Yii2隐藏frontend/web和backend/web的方法,希望大家喜欢。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]