Answer the question
In order to leave comments, you need to log in
How to redirect to a mobile subdomain if the site is viewed from a phone?
Hello! The essence of the question is this:
There is a site on opencart. It lies on the domain let's say: domain.com. It is necessary to make it so that when a user enters the site from the phone, he is automatically redirected to m.domain.com Do
the
following things:
Directly after the open head tag, write (connect a special library that recognizes what the user came from)
<script src="/catalog/view/javascript/device.min.js"></script>
<script>
if ( device.mobile() ) {
window.location.href = "http://m.domain.com/";
//window.location = "http://m.domain.com/";
//location.href = 'http://m.domain.com/';
}
</script>
Answer the question
In order to leave comments, you need to log in
Try .htaccess
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
RewriteCond %{HTTP_HOST} !^m\.domen\.com [NC]
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$)
RewriteCond %{HTTP_COOKIE} !^.*mredir=0.*$ [NC]
RewriteRule ^/?(.*) m. domain.com/$1 [L,R,NE,QSA]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question