I am trying to do a canonical redirect from this url
http://www.mysite.com/page.php?id=1&title=aaa
To this: http://www.mysite.com/1_aaa
I wrote this function:
function canonicalRedirect($url)
{
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'GET')
{
$canonical = $url;
if (!preg_match('/'.str_replace('/','\/',$canonical).'/', $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']))
{
header('HTTP/1.0 301 Moved');
header('Cache-Control: no-cache');
header("Location: $canonical");
}
}
}
And in the page.php I put this code:
canonicalRedirect($url);
Retrieving the $url variable from a MySQL query. However when I try to run it I get this error (I am using Firefox): The page isn’t redirecting properly
I am thinking that the page is self-redirecting but how can I solve this problem? Thanks
finally I managed to solve my problem. I rewrited my function like this:
Then in the page.php code I wrote this:
Bye!