cskow
asked on
How do I use Apache to redirect mobile phones to external site without js or php?
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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will post after I get a chance to validate
ASKER
In the end I used this string:
RewriteCond %{HTTP_user_agent} ^(DoCoMo|J-PHONE|KDDI|UP.B rowser|DDI POCKET|.*i Phone.*|.* iPod.*|.*B lackBerry. *|.*Window s.CE.*|.*L G.*|.*HTC. *|.*MOT.*| .*Motorola .*|.*Nokia .*|.*Samsu ng.*|.*Son yEricsson. *|.*Palm.* |.*Symbian .*) [NC]
RewriteRule (.*) http://www.remotesite.com/ [R,L]
RewriteCond %{HTTP_user_agent} ^(DoCoMo|J-PHONE|KDDI|UP.B
RewriteRule (.*) http://www.remotesite.com/ [R,L]
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
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
ASKER
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]