Mar 22

SEO Book

Posted by Jaimie Sirovich on Mar. 22nd, 2006. 1 comments — voice your opinion.

NEED A GREAT WEB SITE? NEED IT TO BE SEARCH-ENGINE-FRIENDLY?

SEO Egghead is a web development firm dedicated to creating custom, search engine optimized web site applications. We specialize in eCommerce and content management web sites that not only render information beautifully to the human, but also satisfy the "third browser" — the search engine. To us, search engines are people too. Click here to talk to us. We'd love to help!
X

I've been asked to write an SEO book from a technological point of view. As part of the process, I will post some of my ideas on this blog. The title is TBD, but it will be a handbook for all the common questions and concerns that a search engine marketer will have addressed entirely from a programming angle. A stress will be placed on showing examples in PHP, and, perhaps, a later edition in ASP. As a first topic, I will discuss the topic of search engine sitemaps. I am not referring to the general concept of a sitemap, though the origin of the idea comes from the obvious advantages that were noticed when people created a page that functioned as an enumeration of all the URLs on a site. I will show a script that creates both files for a dynamic site with flexibility.

As a side-note. Using a sitemap will probably not get you ranked any higher in the SERPs with any certainty. However, what it definately does do is get your site indexed much quicker. In my experience, Google hits your sitemap a few times a day. This can be an edge in terms of getting into the SERPs faster.

First, we need some simple rewrites in our site's root directory:
RewriteEngine On RewriteRule ^sitemap.xml$ /sitemap.php?id=google [PT]
RewriteRule ^urllist.txt$ /sitemap.php?id=yahoo [PT]

The script "sitemap.php" takes a parameter "id." Here is that script.

<?

require_once('./Sitemap.php');

$s = new Sitemap();

$categories Categories::get();
foreach (
$categories as $c) {
    
$s->addItem(Catalog::makeCategoryLink($c['id']), '''weekly');    
}

$pages Pages::get();
foreach (
$pages as $p) {
    
$s->addItem(Catalog::makePageLink($p['primary_category_id'], $p['id']), DB::unixToSQL(strtotime($p['date_updated'])), 'weekly');
}

$s->addItem('http://www.somedomain.com/Somepage.html''''daily');

if (
$_REQUEST['id'] == 'google') {
    echo 
$s->getGoogle();    
} else if (
$_REQUEST['id'] == 'yahoo'){
    echo 
$s->getYahoo();
}

?> And here is the code for the Sitemap class: <?

class Sitemap
{

    function Sitemap($items = array()) 
    {
        
$this->_items $items;
    }
    
    function 
addItem($url$lastmod ''$changefreq ''$priority ''$additional_fields = array())
    {
        
$this->_items[] = array_merge(array('loc' => $url'lastmod' => $lastmod'changefreq' => $changefreq'priority' => $priority), $additional_fields);
    }
    
    function 
getGoogle()
    {
        
ob_start();
        
header('Content-type: text/xml');
        echo 
'<?xml version="1.0" encoding="UTF-8"?>';
        
?>
        <urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
        <? foreach ($this->_items as $i): ?>
            <url>
            <?
            
foreach ($i as $index => $_i) {
                if (!
$_i) continue;
                echo 
"<$index>" Format::escapeXML($_i) . "</$index>";
            }
            
?>
            </url>            
        <? endforeach; ?>        
        </urlset>
          <?
        
return ob_get_clean();    
    }    
        
    function 
getYahoo()
    {
        
ob_start();
        
header('Content-type: text/plain');
        foreach (
$this->_items as $i) {
            echo 
$i['url'] . "\n";
        }
        return 
ob_get_clean();    
    }
    
}

?>

Tell an amigo:
  • Sphinn
  • Digg
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Facebook



Related posts:
RSS Made Even Simpler Syndication isn't only for blogs; it can be used for...
Yahoo API Code <?php /* sample usage: $tree = new xmlTreeParser('sample.xml'); echo '<pre>'; print_r($tree->getTree()); */ class xmlTreeParser {     var $_parser;     var $_xmldata;...
Code for HTML Auditing <? // +———————————————————————-+ // | HTMLParser                                                           | // | Simple HTML Parsing Library                                          | // | Based on Jose Solorzano's Library; his notice is below.              | // +———————————————————————-+ // | Portions Copyright (c) 2004-2005 Jaimie Sirovich                     | // +———————————————————————-+ // | This program is free software; you can redistribute it and/or        |...




"Only One Wise Comment Banged Out Somewhere On The Internet ..."


web designer India

Excellent article. Nice explanation of codes for url rewrite. :)



Care To Bang On The Keys ... ?

BECOME AN EGGHEAD. SUBSCRIBE TO OUR RSS FEED!

Learn to be as nerdy as we are by never missing our latest blog entries. Receive great tips, tricks, and ideas on improving your web site every day! Subscribe via our RSS Feed or use the chicklets in the sidebar.