How do I do like slashdot does when you type in www.slashdot.com and it goes to slashdot.com? The easiest way if there is more then one. Thanks in advance.
if ( !preg_match("/^example.com/i",$_SERVER['HTTP_HOST']) ) { header("HTTP/1.1 301 Moved Permanently"); if (strlen($_SERVER['QUERY_STRING'])>0) { header("location:http://example.com".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']); } else if (stristr($_SERVER['PHP_SELF'],"index")) { header("location:http://example.com/"); } else { header("location:http://example.com".$_SERVER['PHP_SELF']); } exit; } PHP: This way takes care of query strings and forwards the user to the correct page. It also forwards to / as the root document instead of "index".