Yii2隐藏frontend/web和backend/web的方法
框架(架构)  /  管理员 发布于 7年前   287
Yii 是一个高性能,基于组件的 PHP 框架,用于快速开发现代 Web 应用程序。名字 Yii (读作 `易`)在中文里有 “极致简单与不断演变” 两重含义,也可看作 **Yes It Is**! 的缩写。 Create .htaccess file in root folder, i.e advanced/.htaccess and write below code. 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. Installing component. Write below code in frontend/config/main.php and backend/config/main.phpfiles respectively. create .htaccess file in web directory Note: make sure you have enabled your mod rewrite in apache in local server 以上是高级版的Advanced配置方法,基础版的不需要这样配置。 Advanced和 basic 最大的区别就是分离了前后台 分别是 backend目录和frontend目录 这两个目录实际相对于 basic 来说其实就是两个Yii应用 他们公用的比如Model部分都存放在Common目录 这种高级应用适用于比较复杂大型的项目用于彻底分离开前后台业务逻辑 因此访问前后台就相当于访问两个不同的应用 以上所述是小编给大家分享的Yii2隐藏frontend/web和backend/web的方法,希望大家喜欢。Options +FollowSymlinksRewriteEngine On# deal with admin firstRewriteCond %{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.phpRewriteCond %{REQUEST_FILENAME} !-f [OR]RewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^.*$ frontend/web/index.php
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(); } }}
//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,],
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?/$1 [L]
Thats it! You can try your project with www.project.com/admin, www.project.com
localhost/project_name/admin, localhost/project_name
因此在配置Vhost webroot 目录的时候 假设域名为 www.xxx.com 那么 www.xxx.com指向前台目录 /frontend/web/
配置二级域名root.xxx.com 指向/backend/web/您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号