php - Redirect a site to a Mobile version, error with Google Mobile-Friendly Test -


i have following urls :

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

i redirect people on mobile : domain.fr/m/

in php, 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 check domain.fr google mobile-friendly test, error message :

enter image description here

(it's google can't check if mobile friendly)

if remove php above, google can test says domain.fr not user-friendly.

how make redirection mobile site, think it's problem php code, idea ?

i think have bug in code, try analyze logs of web server.

i have test @ google mobile-friendly test , in google page speed, 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 mac os x) applewebkit/600.1.4 (khtml, 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 mac os x) applewebkit/600.1.4 (khtml, 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 $e ) {             if( strpos( $instring , $e ) !== false )                 return true;         }         return false;     } else {         return ( strpos( $instring , $inarray ) !== false );     } } 

but recomend use nginx such redirection


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -