Information Technology Reference
In-Depth Information
Listing 6-4. an example .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
RewriteRule ^(.*)$ http://android.yoursitesurl.com [ R=301]
</IfModule>
The preceding code first checks to see if your Apache server supports the rewrite code,
then it turns on the rewrite engine and sets up a condition and a rule. The condition
checks for Android in the user agent, and if found, the rule tells the web browser to
redirect the request to http://android.yoursiteurl.com in stead of your usual
http://yoursiteurl.com (o r whatever else the user typed in).
This type of detection is very powerful, and one that can annoy some users. While users
can disable JavaScript detection by turning off JavaScript, .htaccess and PHP user
agent detection can only be 'tricked' by changing the user agent, something that not all
browsers support. (It's worth noting that the Dolphin HD Browser, which is free, allows
one to switch their user agent easily between Android, iOS, and Desktop, making it
useful for testing and tricking!) Furthermore, it's possible that users may want to view
the full web page in their Android browser, and while the PHP method allows you to
provide some sort of toggle code-wise (i.e., a link the user could click that would set a
PHP Session variable telling your code not to show the mobile site), the .htaccess user
agent detection does not allow this. However, in simple situations, the .htaccess
solution is the easiest to configure. Choose your detection method wisely!
Summary
Congratulations! You have made it through yet another chapter, and with your newfound
knowledge Viewports and user agent strings, you will be better equipped to handle
certain pesky user interface problems that might crop up from time to time. Even though
this topic is mostly focusing on building web applications for Android devices, it would
just be foolish to think that you will never run into a situation where you will need to
develop something that works across all platforms. Using what we've talked about
there, you can custom tailor a solution for your app that is efficient and elegant!
 
Search WWH ::




Custom Search