php www to non www redirect

Solutions on MaxInterview for php www to non www redirect by the best coders in the world

showing results for - "php www to non www redirect"
Céline
14 Jan 2017
1$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
2
3if (preg_match('/www./', $url)){
4
5  $url = str_replace('www.','https://', $url);
6
7  header( "HTTP/1.1 301 Moved Permanently" );
8  header( 'Location: ' . $url );
9  exit;
10}