How to Redirect Users To Your Magento Mobile Website?

The growing significance of owning a mobile-friendly website has motivated people to switch from traditional web portal to one which can operate on multiple mobile devices with varying screen sizes and resolutions. If you’re operating a Magento mobile website, then it becomes quite critical for you to redirect your users to the mobile theme for your site.

Magento E-commerce development has been flourishing in the recent years. More and more entrepreneurs have switched to Magento mobile theme for promoting their business products and services. Even the industry biggie like Zalando has used mobile theme for its corporate website. Continue reading this post to know more about redirecting users to your Magento mobile website.

Also Read: How To Go About Outsourcing Web Design Through Social Media

.htaccess – A viable means of redirecting visitors to the site’s mobile theme
With .htaccess method of redirecting users to a Magento mobile website, you need to redirect using a rewrite. You can do the same using Magento Admin. Also, you can opt for JavaScript for redirecting your customers to the site’s mobile-compatible version. If you do not want your customers to land on the website’s home page rather want them to land directly on the page that they want to visit, then it is highly recommended to use a simple rewrite in .htaccess.

Magento Mobile Website Operation

The code snippet associated with Magento .htaccess redirect to mobile theme is displayed below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
RewriteEngine on
RewriteBase /
# Checking noredirect query string
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
# Setting cookie, then skip the next rule
RewriteRule ^ - [CO=mredir:0:www.samplesite.com]
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
# Check already mobile site
RewriteCond %{HTTP_HOST} !^m\.
# Can not r/w cookie in same request,duplicate condition
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$)
# Checking that we haven't set the cookie before
RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC]
# redirecting to mobile site
RewriteRule ^ http://m.samplesite.com [R,L]

Here’s a look at redirecting Magento visitors on a mobile device using Javascript

You need to start off with creating a store view from the main website. For this, you can use the JS-Redirection-Mobile-Site script available on GitHub. Simply download the redirection-mobile.js, highlight the text, copy it and create a new text document within the folder called “js” and name the folder redirect-to-mobile.js. Now, just paste the below code in the <head> section of the page that you’re looking to redirect your visitors to:

1
2
3
4
<!–redirect to Mobile script–>
<script src=”js/redirect-to-mobile.js” type=”text/javascript”&gt;<script type=”text/javascript”>// <![CDATA[
SA.redirection_mobile ({ mobile_url : “samplesite.com”, });
// ]]></script>

It is recommended to place the above code in the page column of phtml files. But, you can decide a suitable place for the given code snippet on your own.

Conclusion

Irrespective of whether you’ve chosen to hire a Magento developer or have created a Magento portal by yourself, managing multiple redirects for your Magento mobile website is something you need to pay special attention to. I’m sure the above post would have allowed you to dig deeper into the handy techniques of redirecting visitors for your Magento web portal to pages you want them to land on.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s