Wednesday, May 27, 2009

canonical URL

Canonical URL:

Some websites differentiates some.com and www.some.com as two different websites, but actually it is not.

Example:

Justmeans.com
&
www.justmeans.com

Those are just the “same” ones.

Solution:
replace non www URL with www url and redirect it.

$strNewRedirection = preg_replace('/(^http:\/\/www\.|^www\.|^http:\/\/)/', '', $strServerName);
$strNewRedirection = "http://www.".$strNewRedirection.$_SERVER['REQUEST_URI'];
 header("Location: ".$strNewRedirection);
exit();

No comments: