Skip to content

Instantly share code, notes, and snippets.

@rolandinsh
Created September 2, 2012 10:09
Show Gist options
  • Save rolandinsh/3596420 to your computer and use it in GitHub Desktop.
Save rolandinsh/3596420 to your computer and use it in GitHub Desktop.
PHP with/without www
<?php
/* redirect to with/without www version of page
* @date 2012-09-02
*/
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www'){
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment