Ngixn根据手机端与电脑端设备相同地址显示不一样页面内容

描述:
根据用户访问的设备类型,相同的地址显示不一样的内容
好比,电脑上访问http://192.168.0.100/shop/s888_a.html这个页面显示内容是”aaaaa”
而后用手机访问http://192.168.0.100/shop/s888_a.html这个页面内容是“bbbbb”,
但访问的URL连接地址是同样,相同的地址显示不一样的内容。php

需求1:html

电脑访问: 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 (显示这个页面的内容)web

1htm

2it

3table

电脑访问: http://192.168.0.100/shop/s888_a.html  ast

手机访问:  http://192.168.0.100/shop/s888_a.html (URL不变内容改变)配置

           http://192.168.0.100/shop/article-256.html (显示这个页面的内容)rewrite

 

需求2:tab

电脑访问: 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 (显示这个页面的内容)

 

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;

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;

 

#那若是后过来呢,手机端访问内容不变,PC端访问内容改变。

# 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;

}

相关文章
相关标签/搜索