Jump to content

Redirect for mobile devices


JonnoTheDev

Recommended Posts

Need help with following rule. Crappy at mod-rewrite. Need to redirect users to a mobile version of a site if a mobile device is detected. The pages on both sites are identical, so if a user on an iPhone goes to www.foobar.com/test-123.php it will 301 redirect to mobile.foobar.com/test-123.php

 

So far:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^.*(up.browser|up.link|windows\ ce|iPhone|Palm|BlackBerry|iemobile|mini|mmp|symbian|midp|wap|phone|pocket|mobile|pda|psp).*$ [NC]
RewriteRule ^(.*)$ http://www.foobar.com [R=301]

Obviously this just redirects to the root of the mobile domain. Need to redirect to the landing page.

Link to comment
https://forums.phpfreaks.com/topic/194786-redirect-for-mobile-devices/
Share on other sites

Never mind, I think this should work.

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^.*(up.browser|up.link|windows\ ce|iPhone|Palm|BlackBerry|iemobile|mini|mmp|symbian|midp|wap|phone|pocket|mobile|pda|psp).*$ [NC]
RewriteRule ^(.*)$ http://www.foobar.com%{REQUEST_URI} [R=301]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.