How to redirect website to its mobile version ?

Jack London

New member
Joined
Jul 9, 2012
Messages
387
Points
0
Hi all,

How to redirect website to its mobile version when user visits website on their mobile phone ?
 

hoangvu

New member
Joined
Jun 6, 2012
Messages
1,879
Points
0
How to redirect your website to its mobile version

You can try methods below:

Javascript Method
Because mobile phones typically have a small screen width, you can redirect visitors to your mobile site if they have a screen width of less than or equal to 800 pixels. You can use the following code to do this:
Code:
<script type="text/javascript">
	<!--
	if (screen.width <= 800) {
		window.location = "http://m.domain.com";
	}
	//-->
</script>
While testing this on a SAMSUNG smart phone, the screen resolution varied based upon how the phone was held. To get the best results, you may have to test with various smart phones.
Please keep in mind however that if the user does not have javascript enabled, this will not work.

.htaccess redirects
You can use a .htaccess redirect to transfer visitors based upon mime types that their browser accepts. For example, if the user's browser accepts mime types that include WML (Wireless Markup Language), then most likely it is a mobile device.

The code below should be placed in your .htaccess file:
Code:
RewriteEngine On
# Check for mime types commonly accepted by mobile devices
RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^ http://m.domain.com%{REQUEST_URI} [R,L]
 
Newer threads
Replies
3
Views
3,534
Replies
9
Views
4,451
Replies
14
Views
9,470
Latest threads
Replies
0
Views
32
Replies
0
Views
86
Replies
0
Views
77
Replies
1
Views
99
Recommended threads
Replies
1
Views
2,213
Replies
0
Views
2,259
Replies
4
Views
4,031
Replies
11
Views
1,469
Replies
5
Views
2,018

Referral contests

Referral link for :

Sponsors

Latest Blog ArticlesMost Viewed Threads

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top