yii2的高级模板分为backend和frontend,最开始用yii的时候并没怎么在意,就使用了两个域名分别解析前后台。今天无意间看见
可以使用一个域名指向前后台。

1.修改 advanced/backend/config/main.PHP 文件如下:

return [
'homeUrl' => '/admin',
'components' => [
'request' => [
'baseUrl' => '/admin',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
];

2.同样修改 advanced/frontend/config/main.php 文件:

return [
'homeUrl' => '/',
'components' => [
'request' => [
'baseUrl' => '',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
];

3.配置域名解析

<VirtualHost *:80>
ServerName advanced.loc
ServerAlias www.advanced.loc DocumentRoot "/path/to/advanced"
<Directory "/path/to/advanced">
AllowOverride All
</Directory>
</VirtualHost>

4.新建一个.htaccess文件,写入一下内容。放在项目根目录advacnced下

# prevent directory listings
Options -Indexes
# follow symbolic links
Options FollowSymlinks
RewriteEngine on RewriteCond %{REQUEST_URI} ^/admin/$
RewriteRule ^(admin)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT] RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /frontend/web/$1

5.再次新建一个.htaccess文件,写入一下内容,在frontend和backend分别放一个。

# use mod_rewrite for pretty URL support
RewriteEngine on
# if a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward the request to index.php
RewriteRule . index.php

如果服务器是nginx,则更改nginx.cong文件,写入以下内容,具体路径根据自身实际情况进行修改

server {
charset utf-8;
client_max_body_size 200M; listen 80; ## listen for ipv4
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name advanced.loc;
root /path/to/advanced; access_log /path/to/logs/advanced.access.log main buffer=50k;
error_log /path/to/logs/advanced.error.log warn; location / {
root /path/to/advanced/frontend/web; try_files $uri /frontend/web/index.php?$args; # avoiding processing of calls to non-existing static files by Yii
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
access_log off;
expires 360d; try_files $uri =404;
}
} location /admin {
alias /path/to/advanced/backend/web; rewrite ^(/admin)/$ $1 permanent;
try_files $uri /backend/web/index.php?$args;
} # avoiding processing of calls to non-existing static files by Yii
location ~ ^/admin/(.+\.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar))$ {
access_log off;
expires 360d; rewrite ^/admin/(.+)$ /backend/web/$1 break;
rewrite ^/admin/(.+)/(.+)$ /backend/web/$1/$2 break;
try_files $uri =404;
} location ~ \.php$ {
include fastcgi_params;
# check your /etc/php5/fpm/pool.d/www.conf to see if PHP-FPM is listening on a socket or port
fastcgi_pass unix:/var/run/php5-fpm.sock; ## listen for socket
#fastcgi_pass 127.0.0.1:9000; ## listen for port
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
try_files $uri =404;
}
#error_page 404 /404.html; location = /requirements.php {
deny all;
} location ~ \.(ht|svn|git) {
deny all;
}
}

yii2高级模板使用一个域名管理前后台的更多相关文章

  1. Yii2 高级模板不使用Apache配置目录,将前后台入口移到根目录

    刚刚入手Yii2高级模板不久,部署项目时,得部署2个应用,个人感觉很繁琐,就将前后台入口文件全部拿到项目根目录.但是一看,完了,出错了!找教程找不到,还是自己解决吧 为了以后好升级,不改变Yii2核心 ...

  2. Yii2高级模板vendor和application非同级目录部署

    上面是Yii2的高级模板,当我们有多个application的时候,这种高级模板可以可以提供很好的扩展性,多个application共用一份YII2框架,默认情况下,框架和application是在同 ...

  3. Yii2 高级模板 多域名管理问题

    现在在网站中有这种情况,比如有一个 http://frontend.com/tv 需要根据判断用户的 User Agent ,如果用户是手机浏览器的话,则跳转到 http://mobile.com/t ...

  4. 【备忘录】yii2高级模板多个应用启用同一个域名多个栏目

    nginx部署方式,两种写法,本人认为第一种写法没有第二种写法优雅 第一种写法配置文件: server { listen ; server_name youban-dev.jqtest.mopon.c ...

  5. Yii2高级模板的安装

    1.通过composer 安装高级版 C:wampwwwyii>composer create-project --prefer-dist yiisoft/yii2-app-advanced a ...

  6. yii2高级模板安装

    通过 Composer 安装 如果还没有安装 Composer,在 Linux 和 Mac OS X 中可以运行如下命令: curl -sS https://getcomposer.org/insta ...

  7. 对于 yii2 高级模板 生成文件入口

    安装的 advanced 模板web下是没有index.php 方法: 在advanced 目录下有个init.bat 应用程序  双击即可如下 查看advanced 目录 (刷新)如下 已有:

  8. Yii2 高级模板添加更多Application

    单独的前端和后端有时是不够的. 如果需要额外的应用程序,例如博客blog: 1.将frontend复制到blog,环境/ dev / frontend到environments / dev / blo ...

  9. Yii2 高级版新建一个 Api 应用

    原文地址:http://www.getyii.com/topic/28 先在项目的根目录下复制一份 backend 为 api: cp backend/ api -r 拷贝 api 环境 cp -a ...

随机推荐

  1. js_1_变量类型

    js中有哪些变量类型? 数字(包括int和float),字符串,数组(字典,js没有字典类型,把字典看成一个对象) 如何把字符转成数字呢? obj.parseInt()         //  转化成 ...

  2. 8_python连接数据库

    如何用python操作数据库? -- 导入pymysql                    -- import pymysql -- 创建连接                          - ...

  3. C++ 指针大小

    32 位机: 指针大小 sizeof(void*)4字节,32位.例如:0x12345678 64位机: 指针大小: sizeof(void*)8字节,64位.一般只用48位,指针形如:0x12345 ...

  4. test for python urllib

    #!/usr/bin/python import urllib2 import time import logging import threading succCount = 0 failCount ...

  5. linux之cut命令简单用法

    语法 cut [-bn] [file] cut [-c] [file] cut [-df] [file] 使用说明: cut 命令从文件的每一行剪切字节.字符和字段并将这些字节.字符和字段写至标准输出 ...

  6. Core Animation 文档翻译 (第四篇)

    Core Animation 文档翻译(第四篇) 让Layer的content动画起来 核心动画的基础接口以及为拥有Layer的View做的动画扩展接口,使得为Layer制作复杂动画变得简单化.例如改 ...

  7. C# 类型基础(下)

    前面介绍了基本的类型,接下来我们讲讲类型的转换 值类型的两种表现形式:未装箱和已装箱 ,而引用类型总是处于装箱形式 int count = 10; object obj = count; 装箱:值类型 ...

  8. windows Apache服务器配置

    Apache 64位可以而32位不可以 安装Apache服务 注意: 如果没有自己设置Apache服务名,后面都可不跟-n "服务名",即采用默认的服务名称. 必须用管理员提示符打 ...

  9. css正三角倒三角

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  10. 对List中每个对象元素按时间顺序排序

    需求: 需要对List中的每个User按照birthday顺序排序,时间由小到大排列. 代码实现: import java.text.SimpleDateFormat; import java.uti ...