Soon I will start with the mobile version of my website, I already have a place to install as follows:
http://mobile.example.com/
I found a solution here: The best way to redirect mobile devices
^ Everything seems to work just fine, only when I try to do it from my iphone4, it will be redirected only if I enter www in url .. If I leave it, I just get my regular site.
Therefore, I need to redirect the mobile device if the user logs on to www.example.com or example.com
I made some changes to the code and worked almost completely. Now it works for both versions of the url, but I have to update once to get the mobile site. Obviously, I want the redirect to work when they first hit the site. I'm sure something is missing here, let me know what you think. I have aplus.net as my host.
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]
Response to Jon Lin ...
Yes, there are a few more rules in my .htaccess
Defining various types of index pages:
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
Remove .php extension from urls
Options +MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L]
Then it is here, which was entered automatically from 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>