How to know one HTTP_HOST and redirect to another

0

That is, when the HTTP_HOST is equal to site1.com or site02.com it redirects to newite.com

I've tried something like this below. but it did not work.

<?php if ($_SERVER['HTTP_HOST'] == 'site1.com, site02.com'): ?>
  TESTE
<?php endif; ?>
    
asked by anonymous 04.08.2018 / 18:44

2 answers

2

With in_array () looks like this:

<?php 
  $domains = ['www.site01.com','www.site02.com'];

  if ( in_array($_SERVER['SERVER_NAME'],  $domains ) ) {

      // pode adicionar respostas no header depender do que vc precisa

      header('Location: https://www.google.com/');

  } else {

      // faz outra coisa

  } ?>

One more thing, use $_SERVER['SERVER_NAME'] or instead $_SERVER['HTTP_HOST'] is easily manipulated by the client, so depending on your purpose there may be something unexpected.

    
04.08.2018 / 18:59
0

One way is to do this:

if(in_array($_SERVER['HTTP_HOST'], ['site1.com', 'site2.com'])){ //verifica se o valor do HTTP_HOST é um dos sites passados
    header('Location: novosite.com');
    die();
}
    
04.08.2018 / 18:56