Solved

How do I use Apache to redirect mobile phones to external site without js or php?

Posted on 2008-10-27
5
1,992 Views
Last Modified: 2013-11-10
My client is running Apache 2.2.6 on RHEL 5 on i686 arch. I've been tasked with doing a redirect to an external URL if a user connects to our site using a WAP device (or a third site if they're coming in via iPhone) that are hosted by a third party content provider.

I am getting push back from the development team in terms of injecting a .js in front of the index page load, and there is no PHP anywhere in the environment, so I appear to have to fall back onto Apache's capabilities.

The Apache configuration already makes liberal use of mod_rewrite, so rewrites are not a problem. I appear to have a couple of options:

1. some form of RewriteCond %(HTTP_USER_AGENT) where I look for a browser type and redirect  externally with a RewriteRule afterwards. This seems difficult due to the amount of browser types there are on mobile phones. Perhaps there a common string?

Here's a list of agent's I'd probably have to sort through:

http://www.zytrax.com/tech/web/mobile_ids.html

Looks like I could use a couple strings, with contents like like "MIDP" and "240x320". Still not elegant.

2. Some sort of Content Negotiation? I'm not sure how to take this from idea to code.

3. Demand the developers add a .js detection script to be run before initial page rendering. The web application itself runs on JBoss 4.5 with a jre 1.5 container.

Anyone have any tips on this?
0
Comment
Question by:cskow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 250 total points
ID: 22812976
to detect the iphone you will need to look at its USER_AGENT signature to see if has "iPhone" somewhere in it. Thus you will explicitly need to look for that "iPhone" value. As for the other devices, refer to:
http://hungrycoder.xenexbd.com/node/182
0
 

Author Comment

by:cskow
ID: 22815860
I think I will end up using something like this:


RewriteCond %{HTTP_USER_AGENT} *iPhone* [OR]
RewriteCond %{HTTP_USER_AGENT} *BlackBerry* [OR]
RewriteCond %{HTTP_USER_AGENT} *Windows CE* [OR]
RewriteCond %{HTTP_USER_AGENT} *LG* [OR]
RewriteCond %{HTTP_USER_AGENT} *HTC* [OR]
RewriteCond %{HTTP_USER_AGENT} *MOT* [OR]
RewriteCond %{HTTP_USER_AGENT} *Motorola* [OR]
RewriteCond %{HTTP_USER_AGENT} *Nokia* [OR]
RewriteCond %{HTTP_USER_AGENT} *Samsung* [OR]
RewriteCond %{HTTP_USER_AGENT} *SonyEricsson* [OR]
RewriteCond %{HTTP_USER_AGENT} *Palm* [OR]
RewriteCond %{HTTP_USER_AGENT} *Symbian*
RewriteRule ^/$ http://wap.externalsite.com [L,R=301]
0
 

Author Comment

by:cskow
ID: 22815867
I will post after I get a chance to validate
0
 

Author Comment

by:cskow
ID: 22836133
In the end I used this string:

 RewriteCond %{HTTP_user_agent} ^(DoCoMo|J-PHONE|KDDI|UP.Browser|DDIPOCKET|.*iPhone.*|.*iPod.*|.*BlackBerry.*|.*Windows.CE.*|.*LG.*|.*HTC.*|.*MOT.*|.*Motorola.*|.*Nokia.*|.*Samsung.*|.*SonyEricsson.*|.*Palm.*|.*Symbian.*) [NC]
 RewriteRule (.*)  http://www.remotesite.com/ [R,L]
0
 

Expert Comment

by:elvis00
ID: 23255420
Hi,
check the WURFL database on http://wurfl.sourceforge.net/ there you find at least a lot of user agents which you can use as forward rule.

Cheers
Markus
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question