homepage Welcome to WebmasterWorld Guest from 54.205.193.39
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / WebmasterWorld / Accessibility and Usability
Forum Library, Charter, Moderators: ergophobe

Accessibility and Usability Forum

    
Mobile Bidirection Redirect
Source for Mobile Bidirection Redirect
wenwon




msg:4570346
 1:13 pm on May 3, 2013 (gmt 0)

Does anyone know of a place where I can find a mobile bidirection/bidirectional redirect? According to this document:

https://developers.google.com/webmasters/smartphone-sites/redirects

Google is fine with the use of this form of redirect but I'm having a difficult time finding a resource that lists this sort of redirect.

There doesn't seem to be any issue with finding a multitude of unidirectional redirects but I'm trying to provide the best user experience for my desktop users in the event they are directed to a mobile web page.

 

Key_Master




msg:4570404
 4:34 pm on May 3, 2013 (gmt 0)

# Default Template
SetEnvIf Remote_Addr . my_template_file=default

# Change template based on visitor's browser
SetEnvIf User-Agent \biPad\b my_template_file=iPad
SetEnvIf X-WAP-Profile \bNN70\b my_template_file=small-screen

# Allow visitor to override template selection via cookie
SetEnvIf Cookie \bmy_template_file=([^;]+); my_template_file=$1

# Redirect user-agent to selected template
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /cgi-bin/%{ENV:my_template_file}.pl [L]


This is a simple example of a technique I devised to redirect various user-agents in my custom CMS. It allows for an unlimited number of template files and only one redirect (internal) is required. This type of redirection should be used with the Vary: User-Agent header.

I don't know what type of CMS you use, but maybe you can modify this example code for your own use.

wenwon




msg:4570412
 5:05 pm on May 3, 2013 (gmt 0)

Thanks for this. To clarify, in my particular situation, I have two URLs. I have a mobile URL and a desktop URL. With your script, if I'm referred to the mobile URL using a desktop computer, will I be automatically redirected to the desktop version?

Thanks in advance.

Key_Master




msg:4570428
 5:50 pm on May 3, 2013 (gmt 0)

Hard to say with the limited information you've provided. It sounds like you've developed two entirely separate sites for your mobile and desktop users. Is that content generated dynamically or is it all static? Need more information.

I have a mobile url and desktop url too. They just happen to be identical (hence the need for the Vary: User-Agent header). In my CMS, there is only one package module processing the various template files. If you're using a single cgi script to dynamically generate both the desktop and mobile pages, then the example code could probably be configured to work on your site. If not, you probably just need a simple 301 or 302 redirection to send mobile users to the mobile version of your site and vice versa for your desktop vistors.

wenwon




msg:4570438
 7:04 pm on May 3, 2013 (gmt 0)

You're right. I'm developing 2 separate URLs. The desktop version would be the this for example:

www.example.com/test.html

The mobile version would be this:

www.example.com/mobile/test.html

Currently, the site consists of static web pages and I'm not using a CMS at this point. (That'll change in about 8 months though) Do you know of the bidirectional script I would need or do you know of a place where I can find the exact script I need? Would you happen to know of of an example of the 301 redirection script you refer to and would you know of where I can find a bidirectional 301 redirection script? Sorry if I'm botching the information but as you can tell, I'm not technical.

Interesting that you bring up the Vary HTTP header. I have another thread going on this subject here and there seems to be some confusion on exactly what to do with it.

In your opinion, is the Vary HTTP header required for my particular situation? If so, exactly where do I place this Vary HTTP header and exactly what would the script look like?

According to Google's documentation, they indicate this:

Please note that if your site automatically redirects mobile visitors coming to the desktop site to the mobile site, or vice versa, please be sure to configure your server to include the Vary HTTP header

https://developers.google.com/webmasters/smartphone-sites/details

Do you have an opinion on this based upon your experience?

Much appreciated.

Key_Master




msg:4570462
 8:30 pm on May 3, 2013 (gmt 0)

# Redirect mobile devices to mobile url
# Add as many attributes/values as you like...
SetEnvIf User-Agent \b[Mm]obile\b mobile
SetEnvIf X-WAP-Profile . mobile

RewriteCond %{ENV:mobile} ^1$
RewriteCond %{REQUEST_URI} !^/mobile/
RewriteRule (.*) http://www.example.com/mobile/$1 [R=301,L]

RewriteCond %{ENV:mobile} !^1$
RewriteRule ^mobile/(.*) http://www.example.com/$1 [R=301,L]


I think this code would probably work in your case. Yes, you need to use the Vary: User-Agent header. Also check out the following Google annotations for desktop and mobile URLs:

https://developers.google.com/webmasters/smartphone-sites/details

lucy24




msg:4570470
 9:01 pm on May 3, 2013 (gmt 0)

There's more than one way to do it, so you have to make decisions. Are you using subdomains (mobile.example.com) or a subdirectory (www.example.com/mobile/)? Where will the redirect happen? javascript, php-or-equivalent, server? If you've currently got static HTML pages, you're probably looking at a server-side redirect. Apache or That Other Server? If Apache, do you have a preferred module? Code involving mod_setenvif was posted above. If you like mod_rewrite, one pattern is

RewriteCond %{HTTP_USER_AGENT} {here you list the likely UAs, such as iPod/iPhone}
RewriteCond %{REQUEST_URI} !^/mobile
RewriteRule (.*) http://www.example.com/mobile/$1 [R=301,L]

RewriteCond %{HTTP_USER_AGENT} !{same list as before, but this time negative}
RewriteRule ^mobile/(.*) http://www.example.com/$1 [R=301,L]

Again, this is only one possible pattern. And I just typed it in off the top of my head. If you're using subdomains, you'd look at %{HTTP_HOST} instead of %{REQUEST_URI}. Since the pair of rules are mutually exclusive (either A or not-A), list them in order of likelihood, based on actual pattern of visits on your own site. Within each rule, if there is more than one condition, list them in order of likely-to-fail.

In addition to the listed conditions, each version should have a supplementary RewriteCond looking at %{HTTP_COOKIE} so you're not redirecting users who have explicitly asked to use the "wrong" version of the site-- or who have been mis-identified by your code.

wenwon




msg:4571213
 6:25 pm on May 6, 2013 (gmt 0)

Hi there. Thanks to both of you for your very helpful answers. I really appreciate it.

@lucy: I'm using a subdirectory. As I understand it, we're going to be using a javascript method to redirect the user.

I'm not technical so I have no idea if an Apache or server side redirect could be used. I don't know what a preferred module is but I'lll try to find out.

Please forgive my ignorance but I have two questions:

- for the non technical person, exactly where would these redirection scripts go? Would they go in the head of the HTML of every page?

- Based upon the fact that my site is mounted on a dedicated server. Would either of you know exactly what the code would look like for the vary HTTP header and more importantly, where would it go?

I have researched the vary HTTP header that is listed on the Google's developer page but most people I've spoken to (that are reasonably technical) can't verify if I truly need it or what the exact code should be for my website let alone where it goes.

Any additional help you can provide would be greatly appreciated. Thanks in advance.

p.s. Would either of you know of someone or a firm that can be contacted to help me with this?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / Accessibility and Usability
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved