Answers for "php www to non www redirect"

PHP
0

php www to non www redirect

$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

if (preg_match('/www./', $url)){

  $url = str_replace('www.','https://', $url);

  header( "HTTP/1.1 301 Moved Permanently" );
  header( 'Location: ' . $url );
  exit;
}
Posted by: Guest on May-21-2021

Browse Popular Code Answers by Language