Attention! Helicon Tech Blog has moved to

Tuesday, July 6, 2010

mod_seo — next level of SEO-friendliness

No so long ago we've introduced mod_seo module for Helicon Ape and now want to represent it to everyone.

What is it about? — mod_seo offers a new handy way of optimizing your site for search engines.
To cut this story short we’ll show a real-life example — how we applied mod_seo on our forum.

What we need: Helicon Ape, Microsoft SQL Server, forum database.
What we do:
  1. Enable mod_dbd and mod_seo modules in httpd.conf
  2. And use the following lines in .htaccess in the root of our site:

    # Declare  a database driver for the forum database
    DBDriver mssql
    # Include DBDParams string for correct SQL connection.
    DBDParams "Data Source=(local)\SQLDB;Initial Catalog=WebWizForum;User ID=sa;Password=***"
    # Prepare SQL queries to select topic subject by Topic_ID 
    # (taken from request URL) 
    DBDPrepareSQL "SELECT [Subject]     FROM [WebWizForum].[dbo].[tblTopic] 
                   WHERE [Topic_ID] =@KEY" getSeoTopic
    # and forum name by Forum_ID (also taken from request URL)
    # from the corresponding db tables
    DBDPrepareSQL "SELECT [Forum_name]  FROM [WebWizForum].[dbo].[tblForum] 
                   WHERE [Forum_ID] =@KEY" getSeoForum
    # Declare rewrite maps that refer to the prepared sql queries
    RewriteMap SeoTopic   dbd:getSeoTopic
    RewriteMap SeoForum   dbd:getSeoForum
    RewriteMap slug int:slug
    # Replace matched pattern in "a href" tags with substitution 
    # including the forum name taken from the db-driven map based on Forum_ID
    SeoRule forum_topics.asp\?FID=(\d+)$ 
          forum$1-${slug:${SeoForum:$1|not-found}}.html   [Redirect,Scope=A]
    # the same but accounting for page number parameter (PN)
    SeoRule forum_topics.asp\?FID=(\d+)&PN=(\d+)$ 
          forum$1-${slug:${SeoForum:$1|not-found}}-$2.html   [Redirect,Scope=A]
    # Replace matched pattern in "a href" tags with substitution 
    # including the topic name taken from the db-driven map based on Topic_ID
    SeoRule forum_posts.asp\?TID=(\d+)(?:&PN=(\d+)&TPN=(\d+))?(?:&(get=last))?$ 
          $1-${slug:${SeoTopic:$1|not-found}}(?2-$3).html?4\?$4 [Redirect,Scope=A]
  3. Enjoy URLs like
    instead of
    (You may check them both as they are live.)
Note: SeoRule directive has a meaning very close to that of RewriteRule, the only difference being that it replaces links on pages according to the Substitution pattern (not rewrites requested URLs).

If you want something of that kind on your site, don’t hesitate to try mod_seo on your site (remember, Helicon Ape is totally free for up to 3 sites!).

Best regards,
Anton — HeliconTech Team