我一直在阅读有关移动侦测的内容,看起来还有一些不好的事情,
我想知道什么是检测手机和平板电脑的最佳方法,然后让网站将其重定向到专门针对移动设备和平板电脑设备的网页。
任何人都可以指引我使用好的js插件或.htaccess解决方案吗? 然后可能指出两者的好坏,以帮助我决定
这是我在stackoverflow上找到的一个htaccess代码:
RewriteEngine on
RewriteBase /
# Check if this is the noredirect query string
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
# Set a cookie, and skip the next rule
RewriteRule ^ - [CO=mredir:0:www.website.com]
# Check if this looks like a mobile device
# (You could add another [OR] to the second one and add in what you
# had to check, but I believe most mobile devices should send at
# least one of these headers)
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST} !^m\.
# Can not read and write cookie in same request, must duplicate condition
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$)
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC]
# Now redirect to the mobile site
RewriteRule ^ http://m.website.com [R,L]
来自Shaun Russell的
这是一个插件我喜欢这个简单代码的外观:
SA.redirection_mobile ({
mobile_url : "mobile.whatever.com",
tablet_host : "tablet.whatever.com",
});
https://github.com/sebarmeli/JS-Redirection-Mobile-Site
那么你会推荐哪些指针/最佳方法? 提前感谢您提供任何反馈或帮助。
编辑:我知道bootstrap是最好的方式,但不是我目前正在使用这个网站(webgl)。
答案 0 :(得分:1)
我最好的是Apache Mobile Filter或AMF。它是由Idel Fuschini创建并在GNU通用公共许可证(GPL)下分发的开源项目。查看更多http://www.apachemobilefilter.org/
但由于不止一个原因,最好的方法是制作适合任何屏幕而无任何重定向的自举响应设计