Archive

Archive for the ‘Search Engine Optimization’ Category

Search Engine Optimization (SEO) for phpBB URLs

November 20th, 2004 No comments

I recently installed phpBB on HappyMudan.com, a new site my wife and I launched last week. I like phpBB, but it’s not the most search engine friendly bulletin board. I did a little Googling and found this site, which has a few optimization tips and which I highly recommend.

However, one thing it doesn’t include is tips on how to rewrite your urls into more meaningful names. As an example, it’s usually a good idea to have the title of a page in the name of the url because search engines give those keywords more weight. So, for example, we’d like the url http://www.happymudan.com/discuss/viewforum.php?f=4 (which looks pretty meaningless) to be something relevant to the keyword “immigration,” which is the topic for this forum. After a little hacking, I was able to come up with a url of the form http://www.happymudan.com/discuss/forum-Immigration-id_4.html. It’s not perfect, but it’s a lot more meaningful than before.

Fortunately, there are only a couple of places where these kinds of urls are really necessary – the listing of forums and the listing of topics.

As an example, if you have two forums – “derek’s news” and “funny jokes” – you want the urls to be something like:

/derek’s-news.html
/funny-jokes.html

Since phpBB processing all happens in the same directory, we have to add some hints to the urls to tell Apache which script to pass them to. So alter those urls to something like:

/forum-derek’s-news.html
/forum-funny-jokes.html

Further muddying the waters, phpBB allows two different forums to have the exact same name (ditto with topics). So we have to also put the unique forum ID into the url:

/forum-derek’s-news-id_93.html
/forum-funny-jokes-id_234.html

Lastly, forum and post names can have non-standard url characters in them (such as ‘ and &). So we have to urlencode them:

/forum-derek%27s-news-id_93.html
/forum-funny-jokes-id_234.html [no change on this one]

So, how do we do this? It’s actually pretty simple. There are two files to edit.

The first is index.php in the root of your installation. Search for:

$template->assign_block_vars(’catrow.forumrow’

Immediately above this code block, add the following:

//derek’s seo url hack
//use the forum name as part of the url
$forum_name=$forum_data[$j][’forum_name’];
$view_forum_url=trim($forum_name);
//prepend ‘forum’ so we know this url is for viewforum.php
$view_forum_url=’forum-’ . $view_forum_url;
//replace spaces with dashes
$view_forum_url=str_replace(’ ‘,’-’,$view_forum_url);
//replace “/” with dashes – for some reason my (admittedly weak) Apache regex doesn’t like “/”
$view_forum_url=str_replace(’/’,’-’,$view_forum_url);
//append -id_ as a handle for the regex to find the correct forum_id
$view_forum_url = (urlencode($$view_forum_url).”-id_$forum_id”;
//add .html to make it look like a static web page
$view_forum_url .=’.html’;
$view_forum_url=append_sid($view_forum_url);

A few lines below the $template->assign_block_vars section, you should see this:

‘U_VIEWFORUM’ => append_sid(”viewforum.$phpEx?” . POST_FORUM_URL . “=$forum_id”))

Comment this out and replace it with:

‘U_VIEWFORUM’ => $view_forum_url)

Save the file.

Next, open the file viewforum.php. Search for “$view_topic_url = ” without the outer quotes.

Comment out this line using //. Immediately above this code block, add the following lines:

//derek’s seo hack
//use the topic title as part of the url
$view_topic_url=trim($topic_title);
//prepend ‘topic’ so we know this url is for viewtopic.php
$view_topic_url=’topic-’ . $view_topic_url;
//replace spaces with dashes
$view_topic_url=str_replace(’ ‘,’-’,$view_topic_url);
//replace “/” with dashes – for some reason my (admittedly weak) Apache regex doesn’t like “/”
$view_topic_url=str_replace(’/’,’-’,$view_topic_url);
//append -id_ as a handle for the regex to find the correct forum_id
$view_topic_url = urlencode($view_topic_url).”-id_$topic_id”;
//add .html to make it look like a static web page
$view_topic_url .=’.html’;
$view_topic_url=append_sid($view_topic_url);

Save the file. We’re almost done.

Add the lines below to your .htaccess. NOTE: this code assumes your phpBB is in a subdirectory called phpBB. Change the “phpBB” to whatever directory you use, or remove it altogether if phpBB is in your document root:

RewriteEngine On
RewriteRule ^/phpBB/topic-(.*)-id_([0-9]*).html /phpBB/viewtopic.php?t=$2 [QSA]
RewriteRule ^/phpBB/forum-(.*)-id_([0-9]*).html /phpBB/viewforum.php?f=$2 [QSA]

QED, no? At least so far. I hacked this out in a hurry and I suspect the regex is not robust enough for all situations. Let me know if you have problems or improvements and I’ll update them here.

Update: I haven’t tried it yet, but a friend pointed me to this mod for phpBB.

Search Engine Optimization (SEO) with WordPress

November 15th, 2004 No comments

WordPress is a great blogging tool, no doubt about it. (It powers this blog.) What you may not know is that it has some great features for search engine optimization (aka SEO). Here are a few tips on getting the most out of WordPress for SEO.

Optimize the Template

As it happens, the default WordPress template is pretty search engine friendly. In particular, it uses Cascading Style Sheets for positioning, which means there isn’t a lot of crufty <table> markup to bloat your html. However, I would recommend one change to the “out of the box” template: change the title of posts to <h1> instead of <h3>. Why? Because Google places higher emphasis on content that is inside of <h1> tags. If your titles are keyword rich (they should be – look at the title of this post for an example), making this change elevates the post’s importance oh-so-slightly in Google’s eyes.

Making the change is simple. Login to WordPress and click on the “Templates” menu item. Open the index.php file (the default), and search for <h3 class=”storytitle”. Change h3 to h1. Click “Update File” and you’re all set.

Optimize the File Name for Your Post

For added Google mojo, you want the title of your post (which is keyword-rich, remember) to also be the name of the file. When Google sees your keywords in the name of the file, it assumes those keywords must be important. Why else would you name it that way?

By default, WordPress uses query strings for the names of your files, so a post’s URL will look something like http://www.yoursite.com/index.php?page=123. Looking at this, you can’t guess what the post is about, can you? Wouldn’t it be better if it were something like http://www.yoursite.com/search-engine-optimization.html? Google thinks so too.

Happily, it’s pretty easy to configure WordPress do this for you automatically.

First, you need to configure WordPress to show you the “post slug,” which is WordPress’s term for the file name. As an example, the post slug for this post is “search-engine-optimization-seo-with-wordpress.” To do this, click on the Options menu, then click on the “Writing” submenu. Next to “When starting a post, show:” select “Advanced Controls.” Save your changes by clicking the “Update Options” button.

Next you need to configure the permalink structure. The permalink is the link the WordPress generates for a specifc post. For example, the permalink for this post is http://www.askderekscruggs.com/search-engine-optimization-seo-with-wordpress.html. To do this, click again on the Options menu, then on the Permalinks submenu. Scroll down the first text box and enter the following:

%postname%.php

This tells WordPress to use the name of your post in the permalink and add “.php” to the end of it.

Click the button labelled “Update Permalink Structure.” Once it’s done updating, at the bottom of the page you will see a new text box with abunch of code in it that looks something like this:

RewriteEngine On
RewriteBase /
RewriteRule ^categories/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?category_name=$1&feed=$2 [QSA]
RewriteRule ^categories/?(.*) /index.php?category_name=$1 [QSA]
RewriteRule ^author/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?author_name=$1&feed=$2 [QSA]
RewriteRule ^author/?(.*) /index.php?author_name=$1 [QSA]
RewriteRule ^([_0-9a-z-]+).html([0-9]+)?/?$ /index.php?name=$1&page=$2 [QSA]
RewriteRule ^([_0-9a-z-]+).html/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?name=$1&feed=$2 [QSA]
RewriteRule ^([_0-9a-z-]+).html/trackback/?$ /wp-trackback.php?name=$1 [QSA]
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ /wp-feed.php?feed=$1 [QSA]
RewriteRule ^comments/feed/?([_0-9a-z-]+)?/?$ /wp-feed.php?feed=$1&withcomments=1 [QSA]

This is code for Apache’s mod_rewrite functions. Basically, this tells your Apache web server to transform (using the example above) http://www.yoursite.com/search-engine-optimization.html into the format that WordPress understands: http://www.yoursite.com/index.php?page=123

If that seems confusing to you, don’t worry about it. The main thing to know is that you need to copy and paste this text into a text file, name it .htaccess (yes, that’s a period at the beginning of the file name) and place that file in the same directory as your WordPress installation. Assuming you followed these instruction correctly, the changes should take place immediately. Simply navigate to your blog page and click on the permalink to verify that it works. QED, no?

Doing these two things alone will do wonders for your search engine traffic. Give them a try and let me know what you think.