I'm going to be starting on a mobile version of my website soon, already have space set up for it as follows:
I found a solution here: Best way to redirect mobile devices
^ This seems to work just fine except when I try this from my iphone4 it will only redirect if I enter the www in the url.. if I leave it out I just get my regular site.
So I need the mobile redirect to work if the user enters www.example.com OR example.com
I made some modifications to the code and got it almost working. Now it works for both versions of the url but I have to refresh once to get the mobile site. Obviously I want the redirect to work when they first hit the site. I'm sure I'm missing something here, let me know what you think. I have aplus.net as my host btw.
RewriteCond %{HTTP_HOST} ^(www\.example\.com|example\.com) [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^(.*)$ http://mobile.example.com/$1 [L,R=302]
Reponse to Jon Lin...
Yes there are a few other rules in my .htaccess
Defining different index page types:
DirectoryIndex index.html index.htm INDEX.HTML INDEX.HTM Index.html Index.htm default.htm Default.htm index.shtml index.cgi index.php index.php3 index.jsp index.phtml
Removing .php extension from urls
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Then this here which was put in automatically from the cp:
# [ CP Global Redirection - Start ]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{SERVER_NAME} !^www\..*$
RewriteRule ^(.*)$ http://www.%{SERVER_NAME}/$1 [R]
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{SERVER_NAME} !^www\..*$
RewriteRule ^(.*)$ https://www.%{SERVER_NAME}/$1 [R]
</IfModule>
# [ CP Global Redirection - End ]