yii2 中关于隐藏frontend/web和backend/web的方法
测试环境直接通过虚拟环境配置即可,网上很多类似资源
不通过虚拟环境配置进行隐藏
1 进行根目录设置,给其配置根.htacess
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注意,如果访问的网站是存在目录的比如localhost/bb/backend/web 这样的需要对^/替换成^/bb/2 创建相应的变量作为访问目录 common/ components/Request.php
namespacecommoncomponents;classRequest extendsyiiwebRequest { public$web; public$adminUrl; publicfunction getBaseUrl(){ returnstr_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. */ publicfunction resolvePathInfo(){ if($this->getUrl() === $this->adminUrl){ return""; }else{ returnparent::resolvePathInfo(); } }}3 在相应模块frontend/config/main.php and backend/config/main.php文件中添加下列配置
//frontend, under components array"request"=>[ "class"
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 高性能的PHP日志系统 SeasLog
- 下一篇: 本章介绍ubuntu kylin 系统的日志文件
