Solved

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

Posted on 2008-10-27
5
1,986 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 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

820 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