国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Yii2如何隱藏frontend/web和backend/web

2019-11-14 14:36:45
字體:
來源:轉載
供稿:網友

Create .htaccess file in root folder, i.e advanced/.htaccess and write below code.

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

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,        'showScr

create .htaccess 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 

www.project.com/admin, www.project.com

in 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的筒子建議先從basic入手



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 呼和浩特市| 汉沽区| 武平县| 纳雍县| 庆安县| 宁河县| 合江县| 林周县| 沛县| 锦屏县| 新平| 瓦房店市| 汉寿县| 巧家县| 乌鲁木齐县| 勃利县| 漳州市| 齐齐哈尔市| 青川县| 锡林浩特市| 杭州市| 保靖县| 嵊州市| 曲麻莱县| 南召县| 称多县| 疏勒县| 绥化市| 邹平县| 华亭县| 昆明市| 墨脱县| 习水县| 修文县| 和政县| 襄樊市| 淳安县| 梁山县| 盐源县| 通化市| 西畴县|