Ngixn根据手机端与电脑端设备相同地址显示不同页面内容
2017-09-28 00:00
288 查看
摘要: ngixn根据手机端与电脑端设备相同地址显示不同页面内容
描述:
根据用户访问的设备类型,相同的地址显示不同的内容
比如,电脑上访问http://192.168.0.100/shop/s888_a.html这个页面显示内容是”aaaaa”
然后用手机访问http://192.168.0.100/shop/s888_a.html这个页面内容是“bbbbb”,
但访问的URL链接地址是一样,相同的地址显示不同的内容。
需求1:
电脑访问: http://192.168.0.100/shop/s888_a.html 手机访问: http://192.168.0.100/shop/s888_a.html (URL不变内容改变) http://192.168.0.100/shop/article-256.html (显示这个页面的内容)
需求2:
电脑访问: http://192.168.0.100/shop/10086.html 手机访问: http://192.168.0.100/shop/10086.html (URL不变内容改变) http://192.168.0.100/shop/article-512.html (显示这个页面的内容)
Nginx配置:
# 0 是PC端
set $tags '0';
# 1 是手机
if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') {
set $tags '1';
}
if ( $uri ~ ^/shop/s888_a.html){
set $tags "${tags}1";
}
if ( $uri ~ ^/shop/10086.html){
set $tags "${tags}2";
}
# /shop/s888_a.html
if ( $tags = "11" ) {
rewrite . /article.php?mod=info&id=256 last;
}
# /shop/10086.html
if ( $tags = "12" ) {
rewrite . /article.php?mod=info&id=512 last;
}
# 这几条是原来Nginx的伪静态重写
rewrite ^/article-([0-9]+).html$ /article.php?mod=info&id=$1 last;
rewrite ^/shop/s([0-9]+)(\w*)\.html$ /goods.php?goods_id=$1&alias=$2&show=1 last;
rewrite ^/shop/([0-9]+).html$ /goods.php?goods_id=$1 last;
#那如果后过来呢,手机端访问内容不变,PC端访问内容改变。
# 0 是PC端 # 1 是手机端 if ( $tags = "01" ) { rewrite . /article.php?mod=info&id=256 last; }
描述:
根据用户访问的设备类型,相同的地址显示不同的内容
比如,电脑上访问http://192.168.0.100/shop/s888_a.html这个页面显示内容是”aaaaa”
然后用手机访问http://192.168.0.100/shop/s888_a.html这个页面内容是“bbbbb”,
但访问的URL链接地址是一样,相同的地址显示不同的内容。
需求1:
电脑访问: http://192.168.0.100/shop/s888_a.html 手机访问: http://192.168.0.100/shop/s888_a.html (URL不变内容改变) http://192.168.0.100/shop/article-256.html (显示这个页面的内容)
1 2 3 | 电脑访问: http://192.168.0.100/shop/s888_a.html 手机访问: http://192.168.0.100/shop/s888_a.html (URL不变内容改变) http://192.168.0.100/shop/article-256.html (显示这个页面的内容) |
电脑访问: http://192.168.0.100/shop/10086.html 手机访问: http://192.168.0.100/shop/10086.html (URL不变内容改变) http://192.168.0.100/shop/article-512.html (显示这个页面的内容)
1 2 3 | 电脑访问: http://192.168.0.100/shop/10086.html 手机访问: http://192.168.0.100/shop/10086.html (URL不变内容改变) http://192.168.0.100/shop/article-512.html (显示这个页面的内容) |
# 0 是PC端
set $tags '0';
# 1 是手机
if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') {
set $tags '1';
}
if ( $uri ~ ^/shop/s888_a.html){
set $tags "${tags}1";
}
if ( $uri ~ ^/shop/10086.html){
set $tags "${tags}2";
}
# /shop/s888_a.html
if ( $tags = "11" ) {
rewrite . /article.php?mod=info&id=256 last;
}
# /shop/10086.html
if ( $tags = "12" ) {
rewrite . /article.php?mod=info&id=512 last;
}
# 这几条是原来Nginx的伪静态重写
rewrite ^/article-([0-9]+).html$ /article.php?mod=info&id=$1 last;
rewrite ^/shop/s([0-9]+)(\w*)\.html$ /goods.php?goods_id=$1&alias=$2&show=1 last;
rewrite ^/shop/([0-9]+).html$ /goods.php?goods_id=$1 last;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | # 0 是PC端 set $tags '0'; # 1 是手机 if ($http_user_agent ~* '(Android|webOS|iPhone|iPod|BlackBerry)') { set $tags '1'; } if ( $uri ~ ^/shop/s888_a.html){ set $tags "${tags}1"; } if ( $uri ~ ^/shop/10086.html){ set $tags "${tags}2"; } # /shop/s888_a.html if ( $tags = "11" ) { rewrite . /article.php?mod=info&id=256 last; } # /shop/10086.html if ( $tags = "12" ) { rewrite . /article.php?mod=info&id=512 last; } # 这几条是原来Nginx的伪静态重写 rewrite ^/article-([0-9]+).html$ /article.php?mod=info&id=$1 last; rewrite ^/shop/s([0-9]+)(\w*)\.html$ /goods.php?goods_id=$1&alias=$2&show=1 last; rewrite ^/shop/([0-9]+).html$ /goods.php?goods_id=$1 last; |
# 0 是PC端 # 1 是手机端 if ( $tags = "01" ) { rewrite . /article.php?mod=info&id=256 last; }
1 2 3 4 5 | # 0 是PC端 # 1 是手机端 if ( $tags = "01" ) { rewrite . /article.php?mod=info&id=256 last; } |
相关文章推荐
- JSP页面根据后台传值不同显示不同内容
- 根据不同分辨率显示相同web页面
- 点击下拉菜单按钮根据下拉框的值在当前页面显示不同的网页内容。
- 手机和电脑设备判断显示不同的页面
- Delphi实现Listbox中的item根据内容显示不同颜色的方法
- UAP如何根据DeviceFamily显示不同的页面
- VS中对话框中相同位置针对不同应用显示不同内容
- TListbox中的item根据内容显示不同颜色的方法
- Web页面根据不同的分辨率显示不同的图片
- 根据下拉框选择变化显示不同内容
- QuickReport 报表根据字段值来显示不同内容
- drupal中根据不同的内容类型节点显示不同的样式
- Web页面根据不同的分辨率显示不同的图片
- 根据新浪IP库地址,跳到不同城市的二级页面
- ASP判断是否移动设备访问,实现根据电脑或手机跳转到不同的站点
- 根据类别显示不同的页面元素
- javascript 根据select所选项的不同显示和隐藏部分内容
- [置顶] iOS 远程推送 根据后台推送内容的不同跳转指定页面
- 根据URL地址以流的形式获取页面内容