Forum Moderators: coopster

Message Too Old, No Replies

url redirect

based on device

         

abushahin

5:56 pm on Aug 10, 2011 (gmt 0)

10+ Year Member



ok i have a redirect in place that works from my regular site to the mobile site based on device detection. since this one requires a redirect url to be specified its a bit long to go through all and specify one by one.
what i was thinking was since i have all pages in the mobile site all i need to do is append 'mobile' to my url. eg regular url: www.site.com if a moile browser comes it appends: www.mobile.site.com so that would eliminate me going through thousands of pages (db generated) and adding manually.
any ideas appreciated or even one that people are using to redirect to mobile site even with db generated content.

thanks

httpwebwitch

6:16 pm on Aug 12, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



do the redirection in your .htaccess file using a regular expression, and a condition that matches the device user-agent.

RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera" [NC]
RewriteRule ^(.*)$ [mobile.example.com...] [L,R=302]

That's a basic example, with flaws, untested, probably buggy. But there ya go. Search for better code examples on the interweb, lots of bloggers have posted theirs and they'll be better than this one.

lucy24

8:54 pm on Aug 12, 2011 (gmt 0)

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



You don't need the quotation marks :) You may be thinking of BrowserMatch. R=301, not 302, unless you really are planning to rearrange the whole thing in a few weeks. And, oops, what's "opera" doing there?

Leosghost

9:13 pm on Aug 12, 2011 (gmt 0)

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



Opera Mini

Use(ragent)full ;-) site [useragentstring.com...]

lucy24

1:33 am on Aug 13, 2011 (gmt 0)

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



Aha. So let's replace that "opera" with a "mini" unless your aim is to puzzle the user. ("How come this site looks so silly in Opera?") Or, if you're being careful, opera\ mini with escaped space (crucial in htaccess).

abushahin

7:32 pm on Sep 12, 2011 (gmt 0)

10+ Year Member



thanks for that guys appreciate it