0

I'm trying to

  • make a PHP 302 redirect,
  • set the Vary header and
  • set the X-Robots tag

dependently on the screen width. The code snippet i have is

 <script language="javascript">
  if ( $(window).width() < 480 )
   {
     <?php
       {
        header('Vary: User-Agent');
        header("Location:'$_SERVER['REQUEST_URI'].'/index_mobile.html", true, 302);
        header("X-Robots-Tag: noindex,nofollow");
       }
     ?>
   }
 </script>

I don't use a simple Javascript redirect, because i must set the Vary header and additionally the redirect must be explicitly 302.

But it seems, this snippet doesn't work. Does somebody know, how i achieve the goals?

Thank you!

Evgeniy
  • 2,337
  • 2
  • 28
  • 68
  • You cannot set headers after any content is written? – Mouser Feb 11 '15 at 16:49
  • 1
    If you've already sent any content, you can't set any more headers. – Andrei P. Feb 11 '15 at 16:49
  • If you're redirecting with JS, then telling proxies what the limits on the redirect rules are is utterly pointless as they aren't going to paying any attention to the redirect anyway. That said, redirecting to a mobile version instead of using media queries is usually a terrible idea anyway. – Quentin Feb 11 '15 at 16:50
  • http://mobiledetect.net/ – Ram Feb 11 '15 at 16:52

0 Answers0