.htaccess - Redirect a specific url but only on mobile or certain screen sizes -
ok here issue. use cms run ecommerce website. uses mobile site addon when user on phone or ipad. want redirect specific url, when in mobile. keep url same desktop.
example:
redirect /desktop-categories/ site.com/mobile-categories
how do , specify redirect when user on mobile?
first you'll need determine if browser web browser on mobile device or not. because mobile phones typically have small screen width, can redirect visitors mobile site if have screen width of less or equal 800 pixels.
javascript window.location method 1
<script type="text/javascript"> if (screen.width <= 800) { window.location = "http://m.domain.com"; } </script>
you can use .htaccess redirect transfer visitors based upon mime types browser supports. example, if user's browser accepts mime types include wml (wireless markup language), mobile device.
.htaccess url rewrite redirects 1
rewriteengine on # check mime types commonly accepted 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]
redirecting mobile users screen size instead of device type 2
var responsive = { maxphonewidth: 775, maxtabletwidth: 925, //redirect based on configurable max width threshold maxwidthredirect: function (maxwidth, url) { var viewport = this.getwindowsize(); //add exclusion in hash in case desktop viewing intended if (window.location.hash != '#desktop' && viewport.width < maxwidth) window.location.href = url; }, //redirect based on recommended phone width threshold mobileredirect: function (url) { this.maxwidthredirect(this.maxphonewidth, url); }, //redirect based on recommended tablet width threshold tabletredirect: function (url) { this.maxwidthredirect(this.maxtabletwidth, url); }, //determine cross-browser screen size getwindowsize: function () { var w = window, d = document, e = d.documentelement, g = d.getelementsbytagname('body')[0], x = w.innerwidth || e.clientwidth || g.clientwidth, y = w.innerheight || e.clientheight || g.clientheight; return { width: x, height: y }; } };
you can see code in action @ following link , trying different browser sizes.
references
Comments
Post a Comment