Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-27
5
Medium Priority
?
2,015 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
  • 3
5 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 750 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
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…
Integration Management Part 2
Suggested Courses
Course of the Month12 days, 16 hours left to enroll

971 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