How to redirect www.domain.com to domain.com via PHP
Posted by Vincent Isles at Sunday, July 13, 2008At the top of all your PHP files (but for most CMS, this would need only be the index.php file), add this:
if (preg_match('/www\.'.$_SERVER['HTTP_HOST'].'/i', $_SERVER['HTTP_VIA']))
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}
(Change to !preg_match if you want to redirect domain.com to www.domain.com)
Labels: domain names, php
This post has
no comment.
Add your own!
Subscribe to:
Post Comments (Atom)

