Where should I put Mobile detection in .htaccess or php?

I have a mobile version of my website, which is working now, and I want to know where to redirect me. I can only think of redirection using:

  • .htaccess
  • Php

I would like to know which one is better / more efficient? Is there a better way to do this differently than in .htaccess or PHP?

thanks

+7
source share
3 answers

I will vote for Apache.

If you do this at the Apache level (in the .htaccess file, or better yet, in the Apache configuration), then if you have HTML files, the only way I can think of this, is JavaScript; this can be easily removed (e.g. disable javascript).

This also applies to other types of files, such as PDF files, Word documents, MP3 files, etc. It can easily be redirected to a page containing the message "not available for mobile."

Another thing I can think of is a css file if they are different (standard version and mobile version).

+10
source

Definitely PHP. You must allow customers to switch from the mobile version to the full version and vice versa, so some cookies will be used.

Good practice is the full version on www.example.com and the mobile version on different subdomains, m.example.com

+4
source

Having done this in PHP, you can make some automatic adjustments to clarify the same content for mobile viewers, it is not necessary to have completely different copies of your content. This article on mobile-friendly PHP designer gives some details. You probably don't want to follow all the tips he gives, since that has been since the speed of mobile data meant minimal images, but it can give you ideas about the methods you can use to make adjustments.

Basically, it comes down to creating a function to customize the HTML output in any way that is most important to your site. Then you put this function in a single file, which is included on each page through .htaccesss (so I think you are doing both PHP and .htaccess). And part of this inclusion is the use of ob_start(); to run the function on the output page when loading.

0
source

All Articles