最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Yii2隱藏frontend/web和backend/web的方法

 更新時(shí)間:2015年12月12日 10:35:07   作者:jerrylsxu  
這篇文章主要介紹了Yii2隱藏frontend/web和backend/web的方法,需要的朋友可以參考下

Yii 是一個(gè)高性能,基于組件的 PHP 框架,用于快速開(kāi)發(fā)現(xiàn)代 Web 應(yīng)用程序。名字 Yii (讀作 `易`)在中文里有 “極致簡(jiǎn)單與不斷演變” 兩重含義,也可看作 **Yes It Is**! 的縮寫(xiě)。

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?/$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 

以上是高級(jí)版的Advanced配置方法,基礎(chǔ)版的不需要這樣配置。

Advanced和 basic 最大的區(qū)別就是分離了前后臺(tái) 分別是 backend目錄和frontend目錄 這兩個(gè)目錄實(shí)際相對(duì)于 basic 來(lái)說(shuō)其實(shí)就是兩個(gè)Yii應(yīng)用 他們公用的比如Model部分都存放在Common目錄 這種高級(jí)應(yīng)用適用于比較復(fù)雜大型的項(xiàng)目用于徹底分離開(kāi)前后臺(tái)業(yè)務(wù)邏輯 因此訪問(wèn)前后臺(tái)就相當(dāng)于訪問(wèn)兩個(gè)不同的應(yīng)用
因此在配置Vhost webroot 目錄的時(shí)候 假設(shè)域名為 www.xxx.com 那么 www.xxx.com指向前臺(tái)目錄 /frontend/web/
配置二級(jí)域名root.xxx.com 指向/backend/web/

以上所述是小編給大家分享的Yii2隱藏frontend/web和backend/web的方法,希望大家喜歡。

相關(guān)文章

最新評(píng)論

兴安盟| 山丹县| 恩平市| 铜鼓县| 淳化县| 昆山市| 井冈山市| 武川县| 新安县| 慈利县| 镇雄县| 永善县| 布拖县| 商南县| 乌兰浩特市| 关岭| 鸡泽县| 左云县| 巍山| 巴楚县| 洛南县| 葵青区| 湾仔区| 彝良县| 陆河县| 苍南县| 邯郸市| 工布江达县| 平罗县| 威远县| 二连浩特市| 汉沽区| 神农架林区| 定陶县| 河南省| 新沂市| 会泽县| 辽宁省| 阆中市| 陈巴尔虎旗| 仲巴县|