|
Originally published by Linux Journal magazine, printed July 2000
Philip Mikal for Open Source Consulting
Configuring Apache for Wireless Browsers
The usage of cellular phones and other wireless devices has been rising exponentially. Recently, many of these devices have contained Internet-enabled functionality and even Web browsing software. If you run a popular Internet site, it's possible someone has tried to visit it with such a device... and seen nothing! In this column, I'll show you how to configure the Apache Web server to handle these requests successfully.
WAP/WML
The leading Internet implementations on hand-held devices have used the Wireless Application Protocol, WAP. The idea comes from the wireless industry and is based on existing Internet technologies such as IP. Just as I use HTML for my site, mikal.org, I'll now use WML for people visiting my site over WAP.
WML stands for Wireless Markup Language and is based on XML. Similar to HTML, WML is read and interpreted by a browser built into a WAP enabled device.
Apache WML Setup
The first thing I need to do to handle wireless visitors is to inform Apache about the MIME type I'll be using. In listing 1 I add MIME support for the WML file extension to the default MIME type configuration file. This file includes a definition of the most common known MIME types. On my filesystem, it's located at "/etc/mime.types".
Listing 1
Catching Wireless Visitors
I want to catch anyone visiting my website with a wireless browser and send them to my WML page, welcome_wap_user.wml (listing 2). For this purpose I'll use Apache's powerful mod_rewrite module, available in version 1.2 or later. By using this, I can rewrite requested URLs on the fly based upon rule conditions. (It's possible that mod_rewrite isn't already compiled into the server, check the Apache documentation for instructions on doing this.) Specifically, I'll be looking at the HTTP_USER_AGENT and HTTP_ACCEPT environment variables to check for known WAP browsers.
<?xml version="1.0"?>
<!DOCTYPE wml
PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml1_1.1.xml">
<wml>
<card>
<p>
Welcome to mikal.org!
</p>
</card>
</wml>
|
Listing 2 - welcome_wap_user.wml
The mod_rewrite module can be used by placing the appropriate directives, shown in listing 3, in the httpd.conf Apache configuration file. Line 1 turns on the RewriteEngine. Jorrit Waalboer, from the WML Programming list at eGroups.com, provided me with the RewriteCond statements in lines 2-7 to determine if the client is a WAP browser. If RewriteCond matches one of these browsers, RewriteRule tells Apache to serve welcome_wap_user.wml.
RewriteEngine on
# Catch most WAP browsers
RewriteCond %{HTTP_ACCEPT} text/vnd\.wap\.wml [OR]
# WinWAP, WAPjag
RewriteCond %{HTTP_USER_AGENT} wap [OR]
# Nokia emulators (sdk)
RewriteCond %{HTTP_USER_AGENT} 7110
# Rewrite!!
RewriteRule ^[\./](.*)$ /welcome_wap_user.wml [L]
|
Listing 3
To activate these changes, I'll need to restart Apache.
I can now check my site, but I'll need a WAP comptabile device. For this purpose I use the UP.Simulator, part of UP.SDK, the Phone.com Software Development Kit. The UP.SDK supports development of WAP services written in WML.
After a quick check with the UP.Simulator, I see my site is now WAP aware and ready for the future of wireless Internet.
For additional information on WAP, WML, or building a WAP service, visit the sites in listing 4.
Listing 4
|