📜  php www 到非 www 重定向 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:33.233000             🧑  作者: Mango

代码示例1
$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;
}