PDA

View Full Version : www. redirecting to a no sub-domain url of the same url



foodbandlt
17 Dec 2009, 09:17 PM
Lately I've been having problems with cookies and their domains effecting their functionality with the www. subdomain. One of the the methods Ive seen other web designers use to resolve this issue is by redirecting ANY www. subdomain to the same address without the www.. Is there some kind of javascript / PHP script that I can use to check the current URL and redirect them to the same URL without the www.?

OleTom
24 Jun 2010, 02:36 PM
Put above all html Do not put the http://


<?php
$preferreddomain = 'YOURDOMAINNAME.com'; // without www
if ($_SERVER['HTTP_HOST'] != $preferreddomain || preg_match('/www\.'.$preferreddomain.'/i', $_SERVER['HTTP_VIA']))
{ header($_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently');
header("Location: http://" . $preferreddomain . $_SERVER['REQUEST_URI']);
exit();
}
?>

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD>