Apache mod_rewrite can be used to detect whether a browser has a WAP or Smartphone device versus a normal size browser and act accordingly. Here is a method:
Creating variables for different sorts of portable devices:
# Wap devices
BrowserMatch "MIDP" WAP_DEVICE
BrowserMatch "CLDC" WAP_DEVICE
BrowserMatch "UP\." WAP_DEVICE
BrowserMatch "HTC" WAP_DEVICE
BrowserMatch "LG" WAP_DEVICE
BrowserMatch "MOT-" WAP_DEVICE
BrowserMatch "SAGEM-" WAP_DEVICE
BrowserMatch "SGH" WAP_DEVICE
BrowserMatch "PT-GB" WAP_DEVICE
BrowserMatch "SIE-" WAP_DEVICE
BrowserMatch "PDA" WAP_DEVICE
BrowserMatch "P730" WAP_DEVICE
BrowserMatchNoCase "Palm" WAP_DEVICE
BrowserMatchNoCase "Symbian" WAP_DEVICE
BrowserMatchNoCase "BlackBerry" WAP_DEVICE
BrowserMatchNoCase "Android 1." WAP_DEVICE
BrowserMatchNoCase "Android 2." WAP_DEVICE
BrowserMatchNoCase "Android 4." WAP_DEVICE
BrowserMatchNoCase "IEMobile" WAP_DEVICE
BrowserMatchNoCase "webOS" WAP_DEVICE
BrowserMatchNoCase "NetFront" WAP_DEVICE
BrowserMatchNoCase "Omnia" WAP_DEVICE
BrowserMatchNoCase "Nokia" WAP_DEVICE
BrowserMatchNoCase "siemens" WAP_DEVICE
BrowserMatchNoCase "Ericsson" WAP_DEVICE
BrowserMatchNoCase "SHARP" WAP_DEVICE
BrowserMatchNoCase "Vodafone" WAP_DEVICE
BrowserMatchNoCase "Windows CE" WAP_DEVICE
BrowserMatchNoCase "Smartphone" WAP_DEVICE
BrowserMatchNoCase "DoCoMo" WAP_DEVICE
BrowserMatchNoCase "MEDION" WAP_DEVICE
BrowserMatchNoCase "SAMSUNG" WAP_DEVICE
BrowserMatchNoCase "PalmOS" WAP_DEVICE
BrowserMatchNoCase "Sendo" WAP_DEVICE
# iPod/iPhone
BrowserMatchNoCase "iPod" IPOD_DEVICE
BrowserMatchNoCase "iPhone" IPHONE_DEVICE
# Tabltets
BrowserMatchNoCase "Tablet" TABLET_DEVICE
BrowserMatchNoCase "Android 3." TABLET_DEVICE
# Windows phone
BrowserMatchNoCase "Windows Phone OS 7" WIN7_SMART_DEVICE
Redirecting non WAP devices to www portal
RewriteCond %{HTTP_HOST} wap.(.*)
RewriteCond %{env:WAP_DEVICE} !=1
RewriteCond %{env:IPHONE_DEVICE} !=1
RewriteCond %{env:IPOD_DEVICE} !=1
RewriteCond %{HTTP:x-wap-profile} !=1
RewriteRule ^/(.*) http://www.%1/$1 [R,L]
The above rewrite rules are used in the WAP portal configuration and are meaning: If the requesting browser is NONE of the listed UserAgents in the above list, then assume that it’s a normal size desktop/laptop browser and redirect it to the web portal.