Googled indexed some www.www links

Discussion in 'Forum SEO' started by Monkey Wrench, Apr 10, 2012.

  1. Monkey Wrench

    Monkey Wrench Aspirant

    41
    13
    +11
    Due to an error in my .htaccess, Google has indexed some of my links as www.www.domain.com instead of the regular www.domain.com

    I've made a php script, which 301-redirects every request without www.domain.com as "http_host" to www.domain.com while adding the "request_uri" after it.

    PHP:
    www.www.domain.com/forum/member-1.php --> www.domain.com/forum/member-1.php
    Google Webmaster Center doesn't support the removal of links in that way.
    Is this sufficient for Google to get rid of the false links in due time?
     
    1
  2. googleguru

    googleguru Enthusiast

    222
    0
    +8
    can you post the code of that php file and the code in your .htaccess ?

    I think you have made a mess in that two files
     
  3. Monkey Wrench

    Monkey Wrench Aspirant

    41
    13
    +11
    The code in the .htaccess (http:// to http://www redirection) has been removed and replaced by the following PHP script, which does both the desired http://www redirection and correction of existing www.www links

    Code:
    if (strpos($_SERVER['HTTP_HOST'], 'www.MYDOMAIN.com') !== 0) {
        header('HTTP/1.1 301 Moved Permanently');
        header('Location: http://www.MYDOMAIN.com' . $_SERVER['REQUEST_URI']);
        exit();
    }
     
  4. googleguru

    googleguru Enthusiast

    222
    0
    +8
    Code:
    if (strpos($_SERVER['HTTP_HOST'], 'www.MYDOMAIN.com') !== 0) {
        header('HTTP/1.1 301 Moved Permanently');
        header('Location: http://www.MYDOMAIN.com' . $_SERVER['REQUEST_URI']);
        exit();
    }
    I cant find anything wrong in this code .Perhaps you can try with this

    Code:
    if (strpos($_SERVER['HTTP_HOST'], 'MYDOMAIN.com') !== 0) {
        header('HTTP/1.1 301 Moved Permanently');
        header('Location: http://www.MYDOMAIN.com' . $_SERVER['REQUEST_URI']);
        exit();
    }
     
  5. Monkey Wrench

    Monkey Wrench Aspirant

    41
    13
    +11
    I believe I did lose some false Google results with this code =D
    Not all, but it seems to work

    Strpos seems to be overkill btw
     
    Last edited: Apr 18, 2012
Verification:
Draft saved Draft deleted