Link to home
Start Free TrialLog in
Avatar of Mark B
Mark BFlag for United States of America

asked on

.htaccess rule to redirect to mobile URI help needed

Hello, I am needing to redirect website visitors to a mobile site based on the user agent information. I've found below code in research and works ok for iphone and android, but I need to redirect to equivalent pages between the desktop and mobile site. For example, if a mobile visitor lands on www.website.com/page5.html, they need to redirect to m.website.com/page5.html. The below code only redirects mobile visitors to  http://m.website.com.

I've experimented with adding:

RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^ http://m.website.com%{REQUEST_URI} [R,L]

Open in new window


in a few different ways to the below code, but doesn't seem to work. Does anyone know of how I can alter the below working code to redirect to specific pages / URIs?

Thank You!

Current Code:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]

# Now redirect to the mobile site
RewriteRule ^ http://m.website.com [R,L]

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mark Bullock
Mark Bullock
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark B

ASKER

Thank you, that worked!