3

I have the following urls :

domain.fr     (desktop site)
domain.fr/m/  (mobile site)
  • Both urls "point" to each other using"canonical" or "alternate".
  • We can access those urls without problem.

I would like to redirect people on mobile to : domain.fr/m/

in PHP, I tried :

$useragent=$_SERVER['HTTP_USER_AGENT'];

if(preg_match('/(android|bb\d+).+mobile|....',substr($useragent,0,4))){header('Location: http://domain.fr/m/');}

Problem : When I check domain.fr with Google Mobile-Friendly Test, I get this error message :

enter image description here

(it's like Google can't check if this is mobile friendly)

If I remove the PHP above, Google can do the test but says domain.fr is NOT user-friendly.

How to make a redirection to the mobile site, I think it's a problem with the PHP code, any idea ?

Julien
  • 3,743
  • 9
  • 38
  • 67
  • Take a look at http://detectmobilebrowsers.com/ You may regirect in nginx - much faster. In PHP insert exit(); after header('Location:...); – Alexander Altshuler Aug 20 '15 at 16:30
  • And, header('Location: http://domain.fr/m/') redirect to concrete path, if you need to redirect the whole site you should modify original path. – Alexander Altshuler Aug 20 '15 at 16:36
  • May I suggest to go responsive design (Bootstrap, Foundation, getmdl, etc,) instead? This desktop & mobile versions are so 2000s. – Tan Hong Tat Aug 21 '15 at 03:50
  • In the past, before 2010 or earlier, we've had to go with multiple versions (wap, desktop, full size, small size etc.) for various devices because responsive design is still unknown. We have good responsive framework to handle that now, don't go backward to create multiple versions, if possible.. :) – Tan Hong Tat Aug 21 '15 at 07:25
  • indeed the html of the mobile site is completely different than the one for desktop, it serves a different goal, and both are optimized for speed, serving different ressources, the only thing, what's better for seo? I've read articles saying both variants have no impacts, site speed remaining important, is that true? – Julien Aug 21 '15 at 07:31
  • Depending on how you configure, it can be either 1 version or 2 versions. If you redirect to `/m/` for search engines, it will appear as `/m/` in search engine results page, as 1 version. If you have 2 versions (no redirect), will it trigger duplicate content? Speed and mobile-friendly are important. – Tan Hong Tat Aug 21 '15 at 07:46
  • yes search engines will see /m/ for all mobile pages, I use meta tags "alternate" and "canonical" so I think it'll avoid duplicate content, but I didn't find clear analysis that proove that responsive is clearly better for seo, anyway, I really don't understand why google fail to recognize domain.fr as a mobile site with the php test above (if I remove the test, and if I test domain.fr/m/ then google say mobile frendly) – Julien Aug 21 '15 at 08:16
  • @Julien I have to test your website so find out the problem, can I have your url? – Kiyan Aug 22 '15 at 12:47
  • @Kiyan here is my url : http://luckeo.fr – Julien Aug 23 '15 at 12:41

3 Answers3

0

I think you have a bug in your code, try to analyze logs of your web server.

I have test at Google Mobile-friendly test and in Google Page Speed, all works fine.

Nginx logs:

127.0.0.1 - - [22/Aug/2015:16:29:16 +0300] "GET /test.mobile.php HTTP/1.1" 301 18 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12F70 Safari/600.1.4 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
127.0.0.1 - - [22/Aug/2015:16:29:18 +0300] "GET / HTTP/1.1" 200 17211 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12F70 Safari/600.1.4 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

PHP:

$useragent = $_SERVER['HTTP_USER_AGENT'];

$devices = ['iphone', 'android'];
if ( arrayInString( $devices, strtolower( $useragent ) ) ) {
    header("HTTP/1.0 301 Moved Permanently");
    header("Location: http://mysite.ua" . strtolower( $_SERVER['REQUEST_URI'] ) );
    die("Redirect");
}


function arrayInString( $inArray , $inString ) {
    if( is_array( $inArray ) ) {
        foreach( $inArray as $e ) {
            if( strpos( $inString , $e ) !== false )
                return true;
        }
        return false;
    } else {
        return ( strpos( $inString , $inArray ) !== false );
    }
}

But I recomend use nginx for such redirection

Aleksey Solomakha
  • 113
  • 1
  • 1
  • 9
0

@Julien First, do not close Link tag!

<link rel="alternate" href="http://luckeo.fr/m/" media="only screen and (max-width: 640px)">

Alternate "link" its just SEO link, it does not redirect any user. And, you must redirect google and other users to mobile version. Read this article: https://developers.google.com/webmasters/mobile-sites/mobile-seo/common-mistakes/faulty-redirects?hl=fr

You got "dismis" from google tests, because you have some bugs in your php-redirects, try my redirect below

Aleksey Solomakha
  • 113
  • 1
  • 1
  • 9
  • thanks but link tags are not a redirect, it just avoid duplicate content, and about the end of the link tag, it works on other sites with tags closed (and written like this in google examples) – Julien Aug 23 '15 at 15:29
  • Yes, but redirect do not work. try the one that I wrote – Aleksey Solomakha Aug 23 '15 at 15:38
  • indeed the redirection worked, it was simply executed on both mobile and desktop sites, and had to be done only for desktop, otherwise it was infinited.. and google wrote "dismiss", so you were partly right, it was anyway a php redirect problem, I'll give you those 50pts:) – Julien Aug 23 '15 at 15:46
0

okay I found the solution :

The php redirection was correct, but the code was executed for both mobile and desktop sites.

I had to make the redirection only for domain.fr, otherwise the redirection was infinited (executed also when on mobile site), and consequently Google sent this error message "dismiss".. it was not easy to understand..

Julien
  • 3,743
  • 9
  • 38
  • 67