Redirection to mobile site does not work properly

Avatar
  • Answered
Hello, I opened to my site a mobile site using the redirection: but there is a problem, when a surfer find my page on Google such as: http://example.com/article.asp?id=3620 - he redirected to the mobile site homepage instead of to the same page at the mobile site. please advise, Thanks.
Avatar
JacobIMH
Hello, and thanks for your question. We do have a guide on how to redirect users to the mobile version of website that goes a bit more depth in the comments about how you might want to setup this type of redirection. The reason that you're trying to navigate to a specific page and getting redirected to the main home page of your mobile site, is because you're simply detecting if the user's screen is under 500px, then redirecting them to just /mobile. You'd want to redirect those users to the mobile version of the same page they landed on. So you might have some code like this in your article.asp page to handle the specific page:
<script>
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)){
if(document.URL !="http://m.example.com/article.asp?id=3620")
  {
    window.location ="http://m.example.com/article.asp?id=3620";
  }
}
</script>
Please let us know if you had any further questions at all. - Jacob