Page 1 of 2
Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 9:44 am
by nyo
Hi,
I am developing mobile websites and I can redirect mobile visitors to mobile version properly, using one of the three methods: JavaScript, .htaccess and PHP.
At this time, I use .htaccess because not all the mobile devices support JavaScript and it might be disabled by the user. Also, not all the websites are coded in PHP, that's why I cannot use PHP redirect for all cases.
and here is my .htaccess code:
RewriteEngine on
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|andr|audi|aumi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|elai|epoc|eric|hipt|htc|inno|ipad|ipaq|ipho|j2me|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "maui|maxo|mda|midp|mini|mits|mmef|mobi|mot-|moto|mwbp|nec-|netf|newt|noki|oper|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pda|pdxg|phil|play|pluc|pock|port|prox|qtek|qwap|rove|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sda|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|windows ce|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteRule (.*) http://mobileversion.com/ [R,L]
Now I have a "View Full Site" link on the mobile site and I want to send visitors to the full site, if they click that link. Is there a way to do this using only .htaccess (without PHP)? If not, how can I do this with PHP?
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 9:47 am
by jacek
Well, you do have access to the query string, so the link to the full site could be to "?noredirect=1" then you could add a condition for that using RewriteCond
ReqriteCond %{QUERY_STRING} "SOMETHING_ELSE"
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 10:36 am
by nyo
jacek wrote:Well, you do have access to the query string, so the link to the full site could be to "?noredirect=1" then you could add a condition for that using RewriteCond
RewriteCond %{QUERY_STRING} "SOMETHING_ELSE"
Jacek, can you please elaborate a bit more? What's QUERY_STRING and what shall I have as SOMETHING_ELSE? Maybe you could direct me to a source about .htaccess redirection.
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 10:50 am
by jacek
You have
[stynax=text]RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR][/syntax]
already, so I assumed you would know what the something else it.
The query string is the portion of the url after the ?, so for this topic it would be "f=4&t=134".
At a guess you would want something a bit like
RewriteCond %{QUERY_STRING} "!noredirect=1" [NC,OR]
the ! means not, but I am not sure how to use it correctly so this may not work, should give you the idea though
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 11:37 am
by nyo
I used the code below:
RewriteEngine on
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|andr|audi|aumi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|elai|epoc|eric|hipt|htc|inno|ipad|ipaq|ipho|j2me|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "maui|maxo|mda|midp|mini|mits|mmef|mobi|mot-|moto|mwbp|nec-|netf|newt|noki|oper|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pda|pdxg|phil|play|pluc|pock|port|prox|qtek|qwap|rove|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sda|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|windows ce|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteRule (.*) http://mobilesite.com/ [R,L]
RewriteCond %{QUERY_STRING} "mode=desktop" [NC]
RewriteRule (.*) http://www.fullsite.com/ [R,L]
But the problem is, full site is coded in HTML, therefore I cannot use something like <a href="
http://www.fullsite.com/?mode=desktop">View Full Site</a>.
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 11:49 am
by jacek
You can still use the query string with html pages.
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 11:53 am
by nyo
jacek wrote:You can still use the query string with html pages.
You mean "
http://www.fullsite.com/index.html?mode=desktop" will work?
EDIT: It didn't work.
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 12:09 pm
by jacek
well the file will be served.
nailyener wrote:EDIT: It didn't work.
In what way.
to be honest, this would be a lot easier with php
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 12:22 pm
by nyo
jacek wrote:
well the file will be served.
nailyener wrote:EDIT: It didn't work.
In what way.
It doesn't send to desktop version from mobile version.
jacek wrote:to be honest, this would be a lot easier with php
Definitely, but the main site is coded in HTML. And I guess a simple "replace index.html with index.php" approach may ruin the site.
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 12:25 pm
by jacek
You want
RewriteCond %{QUERY_STRING} "!mode=desktop" [NC]
The ! meaning not.
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 1:14 pm
by nyo
jacek wrote:You want
RewriteCond %{QUERY_STRING} "!mode=desktop" [NC]
The ! meaning not.
Ok, now I have this code and it did the redirection from mobile to desktop:
RewriteEngine on
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|andr|audi|aumi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|elai|epoc|eric|hipt|htc|inno|ipad|ipaq|ipho|j2me|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "maui|maxo|mda|midp|mini|mits|mmef|mobi|mot-|moto|mwbp|nec-|netf|newt|noki|oper|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pda|pdxg|phil|play|pluc|pock|port|prox|qtek|qwap|rove|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sda|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|windows ce|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{QUERY_STRING} "!mode=desktop" [NC]
RewriteRule (.*) http://mobile.melekapart.com/ [R,L]
But, the main site looks broken on the mobile phone after the redirect. In desktop browsers, it looks ok though.
mobile.melekapart.com you can see the "Desktop Version" link at the bottom.
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 1:19 pm
by jacek
nailyener wrote:mobile.melekapart.com you can see the "Desktop Version" link at the bottom.
Yeah, and it seems to work
nailyener wrote:But, the main site looks broken on the mobile phone after the redirect. In desktop browsers, it looks ok though.
Is it just a styling issue, mobile browsers tend to be a bit crap ?
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 1:22 pm
by nyo
jacek wrote:Is it just a styling issue, mobile browsers tend to be a bit crap ?
Yes they are, but full site shows ok on mobile phone without the redirection when you use
www.fullsite.com, but when you use
http://www.fullsite.com/index.html?mode=desktop for the redirect, it seems broken.
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 1:24 pm
by jacek
The point of mode-desktop is that it prevents the redirect ...
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 1:30 pm
by nyo
jacek wrote:The point of mode-desktop is that it prevents the redirect ...
Yea, what I am trying to say is that:
Without the redirect, when I visit full site using fullsite.com it shows ok on the mobile phone.
When I upload .htaccess, and visit full site using "Desktop Version" link on the mobile site, it sends to desktop version but the layout seems broken.
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 2:08 pm
by jacek
What is broken about the layout ?
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 2:28 pm
by nyo
Well, you need to see it on mobile phone. It shows question marks etc. Maybe not all the mobile devices show the same thing.
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 2:47 pm
by jacek
nailyener wrote:Well, you need to see it on mobile phone. It shows question marks etc. Maybe not all the mobile devices show the same thing.
it actually looks really good on my phone (HTC Desire HD)
I'm not sure what to suggest, make sure everything is utf8 and the weird ? should go away.
Re: Redirecting Mobile Visitors to the Full Site
Posted: Mon May 16, 2011 3:03 pm
by jacek
nailyener wrote:So, you are saying that when you visited melekapart.com on mobile, it redirected to mobile.melekapart.com and then when you clicked "Desktop Version" it opened the desktop version and everything looks ok? (except flash of course)
If so, that's great. Thank you very much Jacek!
no need to take the discussion private eh.
Actually I get redirected to the mobile site, which looks great. clicking the full sire link shows a load of broken images, so I guess that is what you were talking about ?
Not really sure what would cause this, unless the requests for the images are being redirected to mobile. too
you could try adding a check to make sure you only redirect if a .html page is requested.
Re: Redirecting Mobile Visitors to the Full Site
Posted: Tue May 17, 2011 12:23 pm
by nyo
jacek wrote:Not really sure what would cause this, unless the requests for the images are being redirected to mobile. too
you could try adding a check to make sure you only redirect if a .html page is requested.
You are probably right, I have been searching if anyone else had the same problem but couldn't find anything so far. In short, the new page (http://www.melekapart.com/index.html?mode=desktop) is not able to find the images and display them on mobile. Strange thing is that it works fine on the desktop.
Do you have any idea how to check if only a .html page is requested?
Re: Redirecting Mobile Visitors to the Full Site
Posted: Tue May 17, 2011 2:06 pm
by jacek
Here
RewriteRule (.*) http://mobile.melekapart.com/ [R,L]
you are blindly redirecting everything, you could do something like
RewriteRule (.*)\.html http://mobile.melekapart.com/ [R,L]
I guess.