Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Problem with mobile detection and redirects

mobile detection canonical urls

11:03 pm on Oct 24, 2013 (gmt 0)

New User

joined:Oct 24, 2013
posts: 2
votes: 0

My mobile detection script worked fine up until 2 days ago. Then it stopped. The problem is I'm using canonical url redirects to the www version of my site which seems to interfere with the mobile detection script which should send mobile traffic to the m.Example.com version which is configured for mobile screen sizes.

Here is what my .htaccess looks like. The problem is: all traffic is being forwarded to the m.Example.com mobilve version NOT just mobile browsers.

Any help would be much appreciated.

RewriteEngine on

# Force preferred domain for all requests to this server
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.Example\.com
rewriterule (.*) http://www.Example.com/$1 [R=301,L]

# Redirect client index.html requests to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.html\ HTTP/
RewriteRule index\.html$ http://www.example.com/%1 [R=301,L]

RewriteBase /

RewriteCond %{HTTP_USER_AGENT} (android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge\ |maemo|midp|mmp|mobile.+firefox|netfront|opera\ m(ob|in)i|palm(\ os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows\ (ce|phone)|xda|xiino [NC,OR]

RewriteCond %{HTTP_USER_AGENT} ^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a\ wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r\ |s\ )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1\ u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp(\ i|ip)|hs\-c|ht(c(\-|\ |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac(\ |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt(\ |\/)|klon|kpt\ |kwc\-|kyo(c|k)|le(no|xi)|lg(\ g|\/(k|l|u)|50|54|\-[a-w])|
libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-|\ |o|v)|zz)|mt(50|p1|v\ )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|
pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v\ )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-|\ )|webc|whit|wi(g\ |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-) [NC]

RewriteRule ^$ http://m.Example.com [R,L]

[edited by: Ocean10000 at 4:45 am (utc) on Oct 25, 2013]
[edit reason] Examplified/Delinked/Broke long lines [/edit]

4:38 am on Oct 25, 2013 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
votes: 536

:: wandering off to find moderator to Do Something about those long lines ::

See the Forums charter about using example.com. There are at least two different reasons, one of which goes double in the Apache (also IIS) forum.

The problem is: all traffic is being forwarded to the m.mysite.com mobilve version NOT just mobile browsers.

That would seem to be what you told it to do. "If the requested hostname doesn't start in www.example.com, then redirect." Matter of fact, I can't understand why the rule doesn't lead to an infinite-redirect loop in the case of mobile UAs. Neither the www.example.com nor the m.example.com redirect has a preceding condition to exclude requests for

Incidentally, neither hyphens nor slashes need to be escaped in mod_rewrite.

Is it a temporary redirect ([R] instead of [R=301]) just while you're sorting out the rule?

What happens if someone on a mobile device requests an internal page?

You might want to detour a bit to the mobile-and-responsiveness subforum next door. The rule as written has a colossally long list of UAs to check for on every single request for the front page. There are other possible approaches.

If it were me, I'd make a rule listing only the most common mobiles-- say, iP(od|hone)|Android|Blackberry and maybe one or two more-- with correct capitalization. (I've excluded iPad because users will probably prefer the full version.) Anyone with a more obscure cell phone can use the "mobile site" link which will be visible somewhere on every page-- not only the front page-- alternating with the "regular site" link on all pages of the mobile version.
12:26 pm on Oct 25, 2013 (gmt 0)

New User

joined:Oct 24, 2013
posts: 2
votes: 0

I apologize for the long lines of code and the other broken rule. Ignorance is not an excuse and I should have spent significant time to read the forums charter. I've slapped my own wrists.

The mobile site is completely different than the main site. It's built on WP Touch Pro, so there's no need to worry about "what happens if someone on a mobile device requests an internal page."

What I'm trying to do is make sure the main site, if requested on anything but a mobile, goes to the "www" version.

And, anyone with a mobile goes to the m.example.com version.

I'm sorry I'm not familiar with mod-rewrite enough to understand how to put together what you've suggested. It sounds like a good idea but again, I'd need someone to do it.

Perhaps you could lead me to someone I can pay to do it?

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members