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. WebP 图片实践之路

    我们会从三部分来聊聊webp这个话题. 什么是webp,它有什么用? 使用webp的常规方法以及优劣. 我们是如何用上webp的. PS:如果是对webp有一定了解的朋友,建议直接看第三部分.因为是讲 ...

  2. 易趣:使用MongoDB创建关键业务的多数据中心应用

    eBay:使用MongoDB创建关键业务的多数据中心应用 作为全球前十的零售品牌,eBay的活跃用户有一亿七千多万,并拥有跨越全世界190个市场的10亿购物清单,这样的规模下,eBay绝对不允许出现宕 ...

  3. __init__class的简单使用/理解

    # -*- coding: utf-8 -*- class Student(object): def __init__(self, name, score): #通过定义一个特殊的__init__方法 ...

  4. LAMP_yum安装

    前言,人总是会越来越懒,说真的,我是摸着良心说话的 开始总是喜欢源码安装,因为可以定制,而且能显得有格调(逼格),但是一安装就要半天,还有各种依赖包的安装,各种报错,不忍直视 下面是我摘自晚上的一篇l ...

  5. MySQL相关命令与备份

    不加任何参数直接备份 mysqldump -uroot zabbix >/opt/zabbix.bak.sql 恢复,这样恢复时需要自已创建表 mysql -uroot < zabbix. ...

  6. 使用locate 的正则查询 查找所有main.c

    locate支持正则查询的功能, 只需输入locate -r 正则表达式     即可. 现在我想查找所有main.c怎么做? 打开终端,输入shell: locate -r main.c$ PS:' ...

  7. 浅谈ASP.NET配置文件加密

    在刚刚完成的一个ASP.NET项目中,遇到了这么一个问题,项目部署到生产环境中时,领导要求项目中的配置文件(如web.config,app.config)中不能出现敏感字符,如:数据库连接,等等. 第 ...

  8. 通过SMTP发送邮件的Python代码

    贴上一段用Python开发的发送邮件程序 #coding=UTF-8 import smtplib from email.mime.text import MIMEText smtp_host=&qu ...

  9. 关于.NET C#上传大文件的解决办法

    1.最近在解决问题的时候遇到如何将视频以及语音和图片上传到阿里云的服务器中.但是遇到一些大文件就导致无法进行上传. 2.在将图片进行上传到阿里云的时候先将文件转化为二进制文件,然后通过文件流 的形式进 ...

  10. 事务与隔离级别------《Designing Data-Intensive Applications》读书笔记10

    和数据库打交道的程序员绕不开的话题就是:事务,作为一个简化访问数据库的应用程序的编程模型.通过使用事务,应用程序可以忽略某些潜在的错误场景和并发问题,由数据库负责处理它们.而并非每个应用程序都需要事务 ...