1

in site http://detectmobilebrowsers.com/ i get reg exp to detect mobile browsers by $user_agent

There is a code:

if ($http_user_agent ~* "(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino") {
  set $index_file mobile.html;
}

how i can use this reg exp in map? like this:

map $http_user_agent $index_file {
  ~* "regexp" /mobile.html;
  default /desktop.html;
}

nginx get error nginx: [emerg] invalid number of the map parameters in /etc/nginx/conf.d/prod.conf:2

reg exp contains spaces. if i replace spages to \s then the regex stops working and no phones are detected.

1 Answer 1

2

Solution:

  1. Remove the space after ~*
  2. Remove double quotes around regExp
  3. Replace spaces inside regExp with \s
map $http_user_agent $index_file {
  ~*(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge\s|maemo|midp|mmp|netfront|opera\sm(ob|in)i|palm(\sos)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows\s(ce|phone)|xda|xiino /mobile.html;
  default /desktop.html;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.