nginx、TP框架实现兼容pathinfo和rewrite两种url访问方式
2017-09-05 16:29
656 查看
转载自:http://blog.csdn.net/jo_andy/article/details/52598097
环境:centos7,yum安装的nginx1.10、php-fpm,tp3.2
本方法只需要配置nginx.conf的一个文件就可以支持pathinfo和rewrite两种url访问方式
1、支持rewrite方式:
在 location / 处添加以下代码
2
3
4
5
最终变成
2
3
4
5
6
7
8
9
2.实现pathinfo模式
找到有效的 location ~ .php$那部分
首先,将这个$去掉,
然后里面添加以下两行代码
2
最终变成
2
3
4
5
6
7
8
9
10
3.重启nginx和php-fpm即可使用了
环境:centos7,yum安装的nginx1.10、php-fpm,tp3.2
本方法只需要配置nginx.conf的一个文件就可以支持pathinfo和rewrite两种url访问方式
vim /etc/nginx/nginx.conf1
1、支持rewrite方式:
在 location / 处添加以下代码
if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; }1
2
3
4
5
最终变成
location / {1
root html/code;
index index.php index.html index.htm;
if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; }}
2
3
4
5
6
7
8
9
2.实现pathinfo模式
找到有效的 location ~ .php$那部分
首先,将这个$去掉,
然后里面添加以下两行代码
fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info;1
2
最终变成
location ~ \.php {1
root html/code;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
2
3
4
5
6
7
8
9
10
3.重启nginx和php-fpm即可使用了
service nginx restart service php-fpm restart
相关文章推荐
- nginx、TP框架实现兼容pathinfo和rewrite两种url访问方式
- nginx、TP框架实现兼容pathinfo和rewrite两种url访问方式
- nginx(1.10.2)实现thinkPHP pathinfo和rewrite访问方式
- apache/nginx 开启rewrite模块,实现链接的跳转/nginx上使用TP框架
- Nginx兼容框架的pathinfo模式与URL…
- 用Ajax技术和dwr框架两种方式实现下拉列表的级联效果
- Yii2框架Nginx配置以及修改fastcgi.conf实现URL美化
- Nginx兼容框架的pathinfo模式与URL重写
- tp5 url 线上访问 在nginx 上 出现404错误,解决办法(1.80nginx 配置 pathInfo)
- ReactMix框架是基于ReactNative框架实现的,目标是完全兼容现有的H5开发方式的新一代框架ReactMix
- nginx多域名配置与 pathinfo(/ 文件夹形式) URL访问不支持配置
- Nginx服务器下使用rewrite重写url以实现伪静态的示例
- nginx开启pathinfo模式的两种方式
- nginx + tomcat 集群配置详解, 实现负载均衡 URLRewrite Session复制
- HTTP访问的两种方式(HttpClient+HttpURLConnection)整合汇总对比(转)
- Android DES加解密的两种实现方式 - Java DES与Android DES不兼容问题
- Nginx下使Thinkphp URL模式支持PATHINFO和REWRITE
- HTTP访问的两种方式(HttpClient和HttpURLConnection)
- TinkPHP框架下 两种方式判断访问终端是否是微信浏览器
- Spring AOP 代理实现的两种方式: JDK动态代理 和 Cglib框架动态代理