Keyword reach URLs in 5 minutes

This article is an introduction as well as a detailed guide to new mod_seo module being an integral part of Helicon Ape 3 which is destined to build good-looking URLs based on the application’s DB data or maps without necessity to change anything in its code.

Search Engine Optimization usually means a set of measures to improve web site performance for search engines, and one popular instrument for large electronic sites like forums, blogs, e-shops is Search Engine Friendly (SEF) URLs or Keyword Reach URLs. Such URL usually implies that you will see something like in the address bar instead of Search engines use such keywords in links to better rank pages with these keywords for search requests. Nowadays many web applications support Keyword Reach URLs either internally or by means of mod_rewrite but anyway application level support is required. Many other applications like, for example, version of WebWiz forum we are using on our web site, do not support keywords in links, so we have invented mod_seo to fill in this gap.

The idea is quite easy. Web applications like forums or blogs usually use database to store topics, posts and articles, identify posts by some IDs and use these IDs in links. This database already exists and we can easily connect to it and bind these IDs to the topic titles, where all these valuable keywords are stored.

mod_seo introduces only one directive – SeoRule – with the syntax very close to that of RewriteRule directive in mod_rewrite, but SeoRule rewrites links on pages instead of rewriting requested URLs. Together with RewriteRule and RewriteMap directives and database support (already built into Helicon Ape engine) we can make a configuration to retract keywords from database, put these keywords in the links on pages and then navigate user around the site without changing a single line of code in the web application (forum in our case).

Now we will show you how to turn this into this step by step using our live forum as example.

What we do:

  1. Make sure mod_rewrite, mod_dbd and mod_seo modules are enabled in httpd.conf
    Enabling Helicon Ape modules
  2. Put the following lines into .htaccess in the root of our site:
    DBDriver mssql
    # include DBDParams
    DBDParams "Data Source=(local)\SQLEXPRESS;Initial Catalog=WebWizForum;User ID=sa;Password=*****"
    DBDPrepareSQL "SELECT [Subject]     FROM [WebWizForum].[dbo].[tblTopic]  WHERE [Topic_ID] =@KEY" \
    DBDPrepareSQL "SELECT [Forum_name]  FROM [WebWizForum].[dbo].[tblForum]  WHERE [Forum_ID] =@KEY" \
    RewriteMap SeoTopic dbd:getSeoTopic
    RewriteMap SeoForum dbd:getSeoForum
    RewriteMap slug int:slug
    SeoRule forum_topics\.asp\?FID=(\d+)\&title=([^\s"'$&]*) \
            forum$1-$2.html [Redirect,Scope=A]
    SeoRule forum_topics.asp\?FID=(\d+)&PN=(\d+)$ \
            forum$1-${slug:${SeoForum:$1|not-found}}-$2.html [Redirect,Scope=A]
    SeoRule forum_topics.asp\?FID=(\d+)$ \
            forum$1-${slug:${SeoForum:$1|not-found}}.html [Redirect,Scope=A]
    SeoRule forum_posts.asp\?TID=(\d+)\&title=([^\s"'$&]*)(?:&(get=last#\d+))? \
            $1-$2.html?4\?$4 [Redirect,Scope=A]
    SeoRule forum_posts.asp\?TID=(\d+)(?:\&PN=(\d+)\&TPN=(\d+))?(?:&(get=last#\d+))?$ \
            $1-${slug:${SeoTopic:$1|not-found}}(?2-$3).html?4\?$4 [Redirect,Scope=A]
    #rewrite to the original ones
    RewriteRule forum(\d+)-.*(?:-(\d+))\.html$ /forum/forum_topics.asp\?FID=$1&PN=$2 [NC,QSA,L]
    RewriteRule forum(\d+)-.*\.html$ /forum/forum_topics.asp\?FID=$1 [NC,QSA,L]
    RewriteRule (\d+)-.*(?:-(\d+))\.html$ /forum/forum_posts.asp\?TID=$1&TPN=$2 [NC,QSA]
    RewriteRule (\d+)-.*\.html$ /forum/forum_posts.asp\?TID=$1 [NC,QSA]

Now with explanations:

First we need to declare database maps (RewriteMap with database connection) to use in link replacing rule.

  • Declare Microsoft SQL Server driver:
    DBDriver mssql
  • And include DBDParams string for correct SQL connection
    DBDParams "Data Source=(local)\SQLEXPRESS;Initial Catalog=WebWizForum;User ID=sa;Password=*****"
  • Prepare SQL queries to select proper fields (topic/forum name) from corresponding tables of the forum database. I was using Microsoft SQL Server Management Studio to do this. Though any database management tool will do. A ‘@KEY’ in the query has a special meaning and will be substituted by the key value when map call is executed. Declaration is needed to assign names for the queries to refer to them in RewriteMap declaration. We have choosen getSeoTopic and getSeoForum as names for them.
    DBDPrepareSQL "SELECT [Subject]     FROM [WebWizForum].[dbo].[tblTopic]  WHERE [Topic_ID] =@KEY" \
    DBDPrepareSQL "SELECT [Forum_name]  FROM [WebWizForum].[dbo].[tblForum]  WHERE [Forum_ID] =@KEY" \

    Topics table and corresponding SELECT query
    Topics table and corresponding SELECT query

    Forums table and corresponding SELECT query
    Forums table and corresponding SELECT query

  • Now declare database-driven maps using previously declared queries. These maps will be referred to in subsequent SeoRule directives by their names – SeoTopic and SeoForum.
    RewriteMap SeoTopic dbd:getSeoTopic
    RewriteMap SeoForum dbd:getSeoForum
  • Define slug map that is used to remove special characters from topic names to make our links more friendly for browsers and user eyes.
    RewriteMap slug int:slug
  • Now it is time for SeoRule directives.
    New URL format for main forum pages includes the forum number FID and the forum name taken from the database:
    [Redirect] flag forces requests to old-style links to be redirected to new analogues (for the above link it’s
    [Scope=A] says mod_seo to search and replace URLs in tags only
    SeoRule forum_topics.asp\?FID=(\d+)&PN=(\d+)$ \
            forum$1-${slug:${SeoForum:$1|not-found}}-$2.html   [Redirect,Scope=A]
    SeoRule forum_topics.asp\?FID=(\d+)$ \
            forum$1-${slug:${SeoForum:$1|not-found}}.html   [Redirect,Scope=A]
  • New URL format for topic pages includes the topic number TID (as the topic name is not unique) and the topic name taken from the db:
    [Redirect] flag will deal with its ancestor:
    SeoRule forum_posts.asp\?TID=(\d+)(?:\&PN=(\d+)\&TPN=(\d+))?(?:&(get=last#\d+))?$ \
            $1-${slug:${SeoTopic:$1|not-found}}(?2-$3).html?4\?$4   [Redirect,Scope=A]
  • As the forum engine doesn’t understand the new URL format, we use rewriting to convert it to habitual one, e.g. for forum topics
    RewriteRule ^forum/forum(\d+)-.*(?:-(\d+))\.html$ /forum/forum_topics.asp\?FID=$1&PN=$2 [NC,QSA,L]
    RewriteRule ^forum/forum(\d+)-.*\.html$ /forum/forum_topics.asp\?FID=$1 [NC,QSA,L]

    and for forum posts

    RewriteRule ^forum/(\d+)-.*(?:-(\d+))\.html$ /forum/forum_posts.asp\?TID=$1&TPN=$2 [NC,QSA]
    RewriteRule ^forum/(\d+)-.*\.html$ /forum/forum_posts.asp\?TID=$1 [NC,QSA]
  • The result is a page like this:
    Forum with mod_seo enabled

The pleasant thing is you don’t need to change anything in your application — mod_seo and mod_rewrite take care of all cycle of transformations and you just enjoy the SEF picture.

Same technique can be used for many other database driven applications like forums, blogs or e-shops. Existing database may be used to transform links or new maps can be created.

If you need assistance with doing same thing for your application, you can get a Premium Support Plan from us and our support team will be happy to tailor a custom solution for you!

Best regards,
Yaroslav, Anton — HeliconTech Team

This entry was posted in Helicon Ape and tagged . Bookmark the permalink.

9 Responses to Keyword reach URLs in 5 minutes

  1. roclafamilia says:

    Helpful blog, bookmarked the website with hopes to read more!

  2. GreenGoblin says:

    Really nice information, thanks!

  3. Storourpord says:

    I just sent this post to a bunch of my friends as I agree with most of what you’re saying here and the way you’ve presented it is awesome.

  4. attislado says:

    I just book marked your blog on Digg and StumbleUpon.I enjoy reading your commentaries.

  5. Annasanna says:

    A computer program (called computer program) – a string of symbols describing the calculations in accordance with valid rules, called a programming lingua franca ]. The program is chiefly executed by a computer (in regard to eg, displays the trap point), sometimes undeviatingly – if it is expressed in a jargon understandable as the machinery or indirectly – if it is interpreted by another program (the interpreter). The program can be a arrangement of instructions that specify the modifications of the apparatus but it can also describe the circumspection in another progress (eg, lambda calculus).
    a href=””>Google
    The formal expression of the calculation method in the stamp of hominid language understandable to the source organization is called when the program expressed in machine-readable (that is, past the numbers, and more precise ones and zeros) is called machine structure or binary physique (executable).

    Computer programs can be classified according to their applications. So distingu‚ by narcotic addict applications, operating systems, video games, compilers, and others. Programs embedded interior the seal is referred to as firmware.

  6. Genuinely interesting bless you, I do think your trusty readers will likely want a whole lot more items similar to this carry on the good hard work.

  7. Блог о путешествиях says:

    Thx for this great information that you are sharing with us!!!

  8. Rc helicopter reviews says:

    Very useful info to me, thanks!!

  9. Tim Cole says:

    Incredibly challenging cheers, I believe your followers might want a good deal more writing like this carry on the excellent content.