- This topic is empty.
-
AuthorPosts
-
December 20, 2010 at 4:05 pm #31056Historical Forums UserParticipant
Hello, I’ve created a subdomain ‘mobile’ for my site, and want to redirect mobile device users to that subdomain.
I have written a bit of code for my htaccess file to redirect those devices;
RewriteEngine On
#redirect mobile browsers
RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
RewriteRule ^(.*)$ http://mobile.mysite.com [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*BlackBerry.*$
RewriteRule ^(.*)$ http://mobile.mysite.com [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*Palm.*$
RewriteRule ^(.*)$ http://mobile.mysite.com [R=301]
When I try to access the site this way, however, my mobile device tells me that there were too many redirects.
I’m very confused to say the least. Is http://mobile.mysite.com the same as http://www.mysite.com/mobile ?
If so, how do I direct visitors to the index.html within my mobile subdomain file?Any help would be really appreciated. I can’t find much information on this through Google. Thanks!
December 20, 2010 at 5:30 pm #69373TT_MarkMemberWhere is this .htaccess file placed?
When it says too many redirects I *think* it means that it just keeps redirecting because you have a catch all on the redirect rule..so even though it loads http://mobile.mysite.com, your .htaccess file is telling it to redirect to http://mobile.mysite.com and it does it over and over and over until it gives up.
I’m sure someone can correct me if I am wrong though!
December 20, 2010 at 10:39 pm #69342Historical Forums UserParticipantHi Mark, the .htaccess file is located in my root directory, where my traditional index.html would be.
I’ve been messing around, and I have another question which may help me solve this…
New to using sub-domains, I do not understand how to direct users to an index.html file for a subdomain. For instance, I was hoping that browsing to http://mobile.mywebsite.com would take me to the index.html file located within the mobile subdomain folder. However, it goes nowhere. Similarly, mobile.mywebsite.com/index.html has the same result.
This is driving me nutters – maybe its due to the solstice lunar eclipse we’re experiencing tonight.
December 21, 2010 at 5:32 pm #69304shaun101MemberI’m not a rewrite guru, but first you should check/ensure that mod_rewrite is enabled on your server. You can waste a load of time playing with .htaccess and rewrite rules, as well as make yourself go crazy!!
Try these two, hopefully I am not far off!
EG1
Options +FollowSymlinksRewriteBase /
RewriteCond %{HTTP_HOST} !^http://yourdomain.com$RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteRule .* http://mob.yourdomain.com/ [R]EG2
Options +FollowSymlinks
RewriteEngine on
RewriteBase /RewriteCond %{HTTP_HOST} !^http://yourdomain.com$
RewriteCond %{HTTP_USER_AGENT} “iPhone|android”[NC]
# rewrite rules here
RewriteRule ^(.+)$ http://m.mysite.com/$1 [R=302,NC]December 21, 2010 at 9:54 pm #69314Historical Forums UserParticipantEG2 does nothing for me – EG1 gives me the “too many redirects” error. I’ll leave EG1 up for a bit – go ahead and try it out. http://meetaaronsilber.com should redirect to http://mobile.meetaaronsilber.com
December 22, 2010 at 4:27 am #69264TT_MarkMemberOn a completely unrelated note, your contact form is a thing of beauty.
December 22, 2010 at 2:35 pm #69140Historical Forums UserParticipantawh shucks – thanks Mark. I like parts of it. I’ll probably redesign it once I get the blog, freebies section, about page, and mobile site up and rolling. Its feels great to get some feedback – I left a position as a General Manager for Hollister 8 months ago to pursue a career in this industry. A bit of a gamble, but its working out well – just lonely being a freelance guy.
December 22, 2010 at 2:51 pm #69111Historical Forums UserParticipantI feel like .htaccess isn’t the right way to approach this – perhaps a .htaccess redirect to a index.php which redirects mobile to the mobile subdirectory index.html, and everything else to the root index.html. How do companies implement this in the real world?
January 5, 2011 at 11:44 am #67347skiingtahoeMemberAaron,
Have you found a solution? I’m having the same exact issue.
Thanks!
January 5, 2011 at 2:34 pm #67356Historical Forums UserParticipantskiingtahoe – nope. It was driving me nuts and I was wasting way too much time trying to hash out different implementations. There are some device-detection services available on the web which will redirect, but I’m not about to start trying them all.
I’ve read a few articles talking about the different ways to consider redirecting mobile visitors, but nothing covering how to dev and implement those features. If I figure this out for good, I’ll write a tutorial one day.
Chris Coyier, if you’re reading this, a tutorial covering the “why” and “how” of mobile redirects would be awesome. When to redirect, the right way to do it (providing visitors with a link to “full-site”, premalinks, etc…), and how to do it.
-
AuthorPosts
- The forum ‘Other’ is closed to new topics and replies.