Forum Moderators: phranque

Message Too Old, No Replies

Rewrite engine optimization

         

Jake1234

6:11 pm on Jul 24, 2012 (gmt 0)

10+ Year Member



I have a requirement where I have to redirect based on the mobile device type. I am using
RewriteCond %{REQUEST_URI} !^/mobile
RewriteCond %{HTTP_USER_AGENT} "BlackBerry|Opera|Palm|Symbian|iPhone|iPod" [NC]
RewriteCond %{REQUEST_URI} ^/homepage/login
RewriteRule .? [%{HTTP_HOST}%1...] [R=301,L]

For Android though I have to redirect only if it's a mobile and not tablet. So I have

RewriteCond %{REQUEST_URI} !^/mobile
RewriteCond %{HTTP_USER_AGENT} "Android" [NC]
RewriteCond %{HTTP_USER_AGENT} "Mobile" [NC]
RewriteCond %{REQUEST_URI} ^/homepage/login
RewriteRule .? [%{HTTP_HOST}%1...] [R=301,L]

Right now I have these 2 conditions separated and they work like a charm. However, I am trying to figure it out how can I combine them and make the rewrite conditions cleaner, and faster from performance standpoint.

Any help in optimizing this is appreciated.

lucy24

6:24 pm on Jul 24, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I realize this doesn't address your question but I gotta say: What's that {HTTP_HOST} doing there? Unless you have multiple sites passing through the same RewriteRule, one job of any redirect is to get everyone on the same page: with or without www, without any trailing port numbers. So you give the full domain name explicitly.

If you putter around other posts in this forum, you may find that the trend is away from looking at specific UAs. There are simply too many of them. Instead, use the screen resolution as the basis for your redirect. Little ones get redirected; big ones stay where they are. Name doesn't matter.