topical media & game development

talk show tell print

professional-search-06-seophp-include-url-redirect.inc.php / php



  <?php
  
  // load the URL factory library
  require_once 'url_factory.inc.php';
  
  // redirect requests to index.php and index.html to the root
  function fix_index_url()
  {
    // if the request is for index.php we redirect to ./
    if (preg_match('#(.*)index\.(html|php)#', _SERVER['REQUEST_URI'], captures))
    {
      // perform a 301 redirect to the new URL
      header('HTTP/1.1 301 Moved Permanently');
      header('Location: ' . captures[1]);
    }
  }
  
  // redirects to proper URL if not already there
  function fix_category_product_url()
  {   
    // obtain the proper URL of the current category/product page
    proper_url = get_proper_category_product_url();
  
    // 301 redirect to the proper URL if necessary
    if (SITE_DOMAIN . _SERVER['REQUEST_URI'] != proper_url) 
    { 
      header('HTTP/1.1 301 Moved Permanently');
      header('Location: ' . proper_url);
      exit();     
    }
  }
  
  // returns the proper keyword-rich URL 
  function get_proper_category_product_url()
  {
    // retrieve product and category IDs from the query string
    product_id = _GET['product_id'];
    category_id = _GET['category_id'];
  
    // retrieve product and category names from fictional database
    product_name = GLOBALS['products'][product_id];
    category_name = GLOBALS['categories'][category_id];
  
    // create keyword-rich URL
    proper_url = make_category_product_url(category_name, category_id, 
                                            product_name, product_id);
  
    // redirect to keyword-rich URL if not already there
    return proper_url;
  }
  
  ?>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.