Mobile redirect with .htaccess for www.example.com OR example.com

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> # [ CP Global Redirection - End ] 
+4
source share
1 answer

Below is the mobile forwarding code that we use on our Aplus.net platform for our mobile application. You should be able to use this to redirect to your own site.

 RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} !^.*[^/]$ RewriteCond %{REQUEST_URI} !^.*//.*$ RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{QUERY_STRING} !.*=.* RewriteCond %{HTTP:X-WAP-PROFILE} !^$ [OR] RewriteCond %{HTTP:PROFILE} !^$ [OR] RewriteCond %{HTTP_USER_AGENT} ^.*(Alcatel|Asus|Android|BlackBerry|Ericsson|Fly|Huawei|i-mate|iPAQ|iPhone|iPod|LG-|LGE-|MDS_|MOT-|Nokia|Palm|Panasonic|Pantech|Philips|Sagem|Samsung|Sharp|SIE-|Symbian|Vodafone|Voxtel|WebOS|Windows\s+CE|ZTE-|Zune).*$ [NC,OR] RewriteCond %{HTTP_ACCEPT} application/vnd.wap.xhtml\+xml [NC,OR] RewriteCond %{HTTP_ACCEPT} text/vnd.wap.wml [NC] RewriteCond %{SERVER_PORT} !^443$ RewriteCond %{SERVER_NAME} ^www\.(.*)$ RewriteRule ^(.*) http://mobile.%1/ [L] RewriteCond %{REQUEST_URI} !^.*[^/]$ RewriteCond %{REQUEST_URI} !^.*//.*$ RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{QUERY_STRING} !.*=.* RewriteCond %{HTTP:X-WAP-PROFILE} !^$ [OR] RewriteCond %{HTTP:PROFILE} !^$ [OR] RewriteCond %{HTTP_USER_AGENT} ^.*(Alcatel|Asus|Android|BlackBerry|Ericsson|Fly|Huawei|i-mate|iPAQ|iPhone|iPod|LG-|LGE-|MDS_|MOT-|Nokia|Palm|Panasonic|Pantech|Philips|Sagem|Samsung|Sharp|SIE-|Symbian|Vodafone|Voxtel|WebOS|Windows\s+CE|ZTE-|Zune).*$ [NC,OR] RewriteCond %{HTTP_ACCEPT} application/vnd.wap.xhtml\+xml [NC,OR] RewriteCond %{HTTP_ACCEPT} text/vnd.wap.wml [NC] RewriteRule ^(.*) http://mobile.%{HTTP_HOST}/ [L] 
0
source

All Articles