Everything ok with this PHP 301 redirect?

Discussion in 'Google' started by ernest1a, Oct 28, 2009.

  1. #1
    I am changing urls and I would like to redirect already indexed page. For example domainname.com/categoryname/example.php?page=4 to domainname.com/categoryname/4.html. My code is below, please tell me if this is ok and safe for SEO.

    
    if (strpos($_SERVER['REQUEST_URI'],"example.php") ) { 
    $string=$_SERVER['REQUEST_URI'];
    $parts = explode ('/', $string);
    $categoryname=$parts[1];
     header('HTTP/1.1 301 Moved Permanently');
     header('Location: http://www.domainname.com/'.$categoryname.'/'.$_GET[page].'.html');
    }
    
    PHP:

     
    ernest1a, Oct 28, 2009 IP
  2. dipali

    dipali Peon

    Messages:
    450
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you changed from .php to .html than take following steps to switch without losing ranking of those pages

    There are two ways to do this:

    - Tell Apache to parse all .php files a .html file. to do this, place this code in your httpd.conf file:
    Code:
    AddType application/x-httpd-php .php .html

    - Use a 301 redirect to redirect from the .php files to the .html files.
    Code:
    RedirectMatch 301 ^/(.*)\.html$ http://www.yourdomain.com/$1.php
     
    dipali, Oct 28, 2009 IP