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".

text/vnd.wap.wml wml
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.

http://updev.phone.com/
http://wap.colorline.no/wap-faq/
http://www.wapforum.org/
http://www.waplinks.com/
http://www.egroups.com/group/wmlprogramming
Listing 4

Tony Hansmann To Address Goldman Sachs Investor Conference. (10/28/05)
Andrew Larsen hired as Vice President, Business Development. (03/21/05)
Level Acuity merges with Precept Consulting and relaunches as Open Source Consulting, LLC (11/01/04)
Level Acuity aquires employment website DBAJobs.com. (06/01/04)
Level Acuity sponsors January's meeting of the San Francisco Perl Mongers. (01/02/04)
Marketing campaign launched featuring ads on Perl.com and Google. (11/13/03)
Level Acuity, LLC announces the launch of their website. (11/11/03)

Contact us today!
+1-877-490-6030 (o)
+1-415-294-4429 (o)
+1-415-358-5887 (f)

Copyright © 2003-2005 Open Source Consulting, LLC. All rights reserved.