Yii2隐藏frontend/web和backend/web的方法
Yii 是一个高性能,基于组件的 PHP 框架,用于快速开发现代 Web 应用程序。名字 Yii (读作 `易`)在中文里有 “极致简单与不断演变” 两重含义,也可看作 Yes It Is! 的缩写。
Create .htaess file in root folder, i.e advanced/.htaess 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 ponents/Request.php file in mon directory and write below code in this file.
namespace mon\ponents; 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./admin Would work: site./admin/ Using this function, both will work. / public function resolvePathInfo(){ if($this->getUrl() === $this->adminUrl){ return ""; }else{ return parent::resolvePathInfo(); } } }
Installing ponent. Write below code in frontend/config/main.php and backend/config/main.phpfiles respectively.
//frontend, under ponents array 'request'=>[ 'class' => 'mon\ponents\Request', 'web'=> '/frontend/web' ], 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, ], // backend, under ponents array 'request'=>[ 'class' => 'mon\ponents\Request', 'web'=> '/backend/web', 'adminUrl' => '/admin' ], 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, ],
create .htaess file in web directory
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.)$ /index.php?/$1 [L]
Note: make sure you have enabled your mod rewrite in apache
Thats it! You can try your project with
.project./admin, .project.
in local server
localhost/project_name/admin, localhost/project_name
以上是高级版的Advanced配置方法,基础版的不需要这样配置。
Advanced和 basic 最大的区别就是分离了前后台 分别是 backend目录和frontend目录 这两个目录实际相对于 basic 来说其实就是两个Yii应用 他们公用的比如Model部分都存放在Common目录 这种高级应用适用于比较复杂大型的项目用于彻底分离开前后台业务逻辑 访问前后台就相当于访问两个不同的应用
在配置Vhost webroot 目录的时候 假设域名为 那么 指向前台目录 /frontend/web/
配置二级域名root.xxx. 指向/backend/web/
以上所述是长沙网络推广给大家分享的Yii2隐藏frontend/web和backend/web的方法,希望大家喜欢。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程