Ad

Serve Different Pages With The Same URL

- 1 answer

I have two HTML pages. a.html is a mobile version of my site, b.html is the desktop version. How can I set these two pages to use the same URL?

Ad

Answer

It is very easy and I have already implemented this. You can check out wittyfeed.com, it serves different files for mobile and desktop.

It can be done as follow,

http {
   ....
   map $http_user_agent $ind {
       "~*mobile" a.html;
       default b.html;
   }


   server {
       ...
       index $ind;
       ...
       location / {
           try_files $uri $uri/ $ind;
       }
   }
}

The above code runs as, it sets value for variable $ind, as a.html if the request comes from mobile or b.html otherwise. Then, accordingly it tries to fetch the file. :)

Edited w.r.t. comment below, *not tested,

http {
   ...
   map $http_user_agent $proxy_addr {
      "~*mobile" test-qa.firebaseapp.com/mobile;
      default  localhost:8080/test/jsp/index.jsp;
   }

   server {
      ...
      location /test {
         proxy_pass $proxy_addr;
      }
   }
}
Ad
source: stackoverflow.com
Ad