Trying out a php 301 server header response for Google

During the last couple of months it has become increasingly important to handle varous calls to your website with extra care. And it’s all about Google. Apparently, Google has a lot of difficulties with treating www.lindqvist.com and lindqvist.com as the same site (which they are).

So, if people tend to link in to a site without the www part (which they do), they will actually confuse Google into thinking that you have two sites with exactly the same content. That’s bad. At least in the eyes of a search engine, which can’t decide on what page to display. So your page will sink through the SERPs in Google and might actually dissapear alltogether…

There are various ways to stop this from happening, most of them including rather difficult scripting in the Apache .htaccess file. But if you are running PHP (which I am) you can actually ad a few lines at the top of your index file, and help Google out by never displaying the wrong page.

This is what I’m doing:

    $webspace = getenv("HTTP_HOST");
    if(!(eregi("www.", $webspace, $regs))) {
    header("HTTP/1.0 301 Moved Permanently");
    header("Location: http://www.".$webspace."/");
    }

It works!

The same code can also be used if you actually move a page permanently. I just used it for pointing search engines in the right direction for the url www.zebragarden.com/site-development.php