Here’s an article I wrote which describes in detail how to accomplish mobile browser device detection and redirection.
Perl/CGI:
https://www.mlynn.org/2010/07/mobile-device-detection-and-redirection-with-perl-and-cgi/
PHP:
https://www.mlynn.org/2010/06/mobile-device-detection-and-redirection-with-php/
I tend to avoid javascript because of the device limitations. These examples will show you how to accomplish detection and redirection without javascript. The code for the examples is freely available at the web site:
https://www.mlynn.org/wp-content/plugins/download-monitor/download.php?id=2
Enjoy!