Yii2项目高级模版 三个模块在同一个目录下的重定向配置
最近做项目用到的,非常好用。
修改 advanced/backend/config/main.PHP 文件如下:
return [
'homeUrl' => '/admin',
'components' => [
'request' => [
'baseUrl' => '/admin',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
];
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
同样修改 advanced/frontend/config/main.php 文件:
return [
'homeUrl' => '/',
'components' => [
'request' => [
'baseUrl' => '',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
];
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
接着设置服务器, 这里先以 apache 为例.
首先设置一下虚拟主机:
<VirtualHost *:80>
ServerName advanced.loc
ServerAlias www.advanced.loc
DocumentRoot "/path/to/advanced"
<Directory "/path/to/advanced">
AllowOverride All
</Directory>
</VirtualHost>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
然后在站点根目录下创建 .htaccess 文件为:
# 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
然后在 advanced/backend/web 目录中创建 .htaccess 文件, 内容如下:
# 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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
然后在 advanced/frontend/web 目录中复制一份上面的.htaccess 文件
Nginx 下的环境配置
Nginx 下的配置可能稍微复杂一些, 这里直接贴出配置, 大家请根据自己的需要进行相应的修改:
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项目高级模版 三个模块在同一个目录下的重定向配置的更多相关文章
- Maven项目如何将自定义文件添加到META-INF目录下
Maven项目如何将自定义文件添加到META-INF目录下 学习了:https://blog.csdn.net/yangjiegreat/article/details/78698655 <bu ...
- Web 项目没有发布到我们安装的tomcat目录下
新手做Web项目的时候,在Ecplise把app发布到tomcat,但最后项目并没有发布到我们自己安装的 tomcat目录下,而是在.metadata\.plugins\org.eclipse.wst ...
- maven小项目注册服务(三)--web模块
java的web应用打包方式一般为war它和jar的区别就是包含了更多的资源和文件,如JSP文件,静态资源文件,servlet等等.war包的核心就WEB-INF文件夹下必须有一个web.xml 的配 ...
- angularJs项目实战!01:模块划分和目录组织
近日来我有幸主导了一个典型的web app开发.该项目从产品层次来说是个典型的CRUD应用,故而我毫不犹豫地采用了grunt + boilerplate + angularjs + bootstrap ...
- 使用os模块实现展示目录下的文件和文件夹
Windows 10家庭中文版,Python 3.6.4 今天学习了os模块,下面是使用它开发的一个展示目录下的文件和文件夹的函数,代码如下: import os # deep大于等于1的整数,默认为 ...
- Yii2.0 高级模版编写使用自定义组件(component)
翻译自:http://www.yiiframework.com/wiki/760/yii-2-0-write-use-a-custom-component-in-yii2-0-advanced-tem ...
- eclipse 项目中的java文件没有在WEB-INF目录下的classes中 生成相对应的编译后的类
1.首先确定project->Build Automatically是否勾选上: 2.执行完第一步之后测试一下看是否能编译,如果还是不能,则进行手动编译: 3,进入clean对话框,选择Cle ...
- python3通过os模块统计指定目录下文件个数
代码: import os path = r"C:\Users\Administrator\Desktop\***" print('filenum:',len([lists for ...
- python os模块获取指定目录下的文件列表
bath_path = r"I:\ner_results\ner_results" dir_list1 = os.listdir(bath_path) for dir1 in di ...
随机推荐
- .Net 读取配置文件 xml
直接解析XML文件 1.System.Xml.Linq命名空间下提供可以使用linq查询的类,使用linq to xml读取也很方便. 2.还可以使用System.Xml.Serialization类 ...
- 将php-fpm添加至service服务
1. 使用命令:cd /usr/local/php/etc,进入etc目录,编辑 php-fpm.conf 文件,将 ;pid = run/php-fpm.pid 前面的分号去掉 2. 重启php- ...
- 环境准备—之—linux下安装jdk
本文大部分转自 https://www.cnblogs.com/Dylansuns/p/6974272.html openjdk与jdk的区别 ----反正不一样,要不名字也不会不相同了 https ...
- 使用Metasploit渗透攻击windows系统(一)
攻击机:kaili ip:192.168.80.157 目标机:win7 IP:192.168.80.158 这里用两种方法去创建meterpreter会话: 1)利用kali中的msfvenom生成 ...
- 【Oracle】【8】大批量update某个字段
正文: 需实现:将A表的某个字段的值复制到B表中 我们一般会这样写:UPDATE B SET B.NAME = (SELECT A.NAME FROM A WHERE A.NO = B.NO) 出现的 ...
- canvas实现点连线动画
给定一系列坐标(x, y)点, 实现将各个点按照先后顺序连接起来的动画.还有两个要求: 1.点与点之间直接用线段连接, 不用考虑曲线 2.动画支持暂停, 继续, 重头开始播放功能 这个功能该怎么实现呢 ...
- jdbc,mysql 数据库BLOB返回值 [B 的问题
当jdbc返回值类型对应的java类型是[B,那就表示返回值的类型比较模糊难以区分: BLOB类型是mysql数据库常用来存储,但是通过getBlob()方法获取值得时候会报错: 错误信息: java ...
- attr VS prop 区别
attr 能够增加.获取.删除页面属性.从页面中获取属性值: prop 用来获取.删除元素自带属性.从属性对象中获取属性值. attr 只获取静态属性值,就是页面加载时的最初的属性值: prop 可以 ...
- [atcoder contest 010] F - Tree Game
[atcoder contest 010] F - Tree Game Time limit : 2sec / Memory limit : 256MB Score : 1600 points Pro ...
- mst总结
1.jsonp跨域 Jsop的原理:利用script不存在跨域的问题,动态创建script标签,把需要请求的数据源地址赋值给其src属性,并且指定一个回调函数,从而接受到我们想要的数据 后台设置下 ...