提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录前言一、开发中遇到一个需求。同一个域名在APP移动端访问跳转APP移动页面,PC访问展示web页面。APP和PC端是两套代码。百度和谷歌了好久。自己总结了下两种?二、代码实例
1.2.读入数据总结
一、APP和PC端两套代码,同一个域名访问? 二、代码实例 1.同一个代码根据不同的客户端访问不同的项目目录
代码如下(示例):
nginx.conf的访问文件中配置
location / {
root /usr/share/nginx/html/pclive; //PC端项目路径
if ($http_user_agent ~* "(mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)") {
root "/usr/share/nginx/html/live"; //移动端项目路径
}
index index.html index.htm;
}
2.
代码如下(示例):
//pc端 Nginx文件配置
server
{
listen 80;
server_name www.xxxx.com;
index index.shtml index.html;
……
//判断如果Pc端网址在app端访问,调用移动端的链接
if ($http_user_agent~*"(mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)")
{
rewrite ^/(.*)$ http://m.xxx.com/$1 permanent;
}
……
}
//移动端 Nginx 配置
server
{
listen 80;
server_name m.xxxx.cn;
index index.shtml index.html;
//判断如果在移动端访问的不是移动端的网址,调用pc端的网址
if ($http_user_agent !~*"(mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)") {
rewrite ^/(.*)$ http://www.xxx.cn/$1 permanent;
}
……
}



