WWW to non-WWW Redirect with PHP
问题 I want to redirect all www.domain.com requests to domain.com with PHP, basically: if (substr($_SERVER[\'SERVER_NAME\'], 0, 4) === \'www.\') { header(\'Location: http://\' . substr($_SERVER[\'SERVER_NAME\'], 4)); exit(); } However I do want to maintain the requested URL like in SO, for e.g.: http://www.stackoverflow.com/questions/tagged/php?foo=bar Should redirect to: http://stackoverflow.com/questions/tagged/php?foo=bar I don\'t want to rely on .htaccess solutions, and I\'m unsure which $