I did a post before regarding Search Engine Optimisation (
SEO) using the TBH template.
A couple of things I implemented were a new MasterBase class that exposed the META Title and Description fields as overridable properties for content pages and also the ability to set default content for these properties within the Web Config file.
As someone pointed out at the time, another important thing with dynamic sites is URL rewriting.
There many reasons for implementing URL rewriting, one being to increase the search relevancy of your pages. Embedding keywords into your URL's and moving from using Querystring arguments to fully qualified URL's can often improve chances of your entire site being indexed and provide better ratings.
There are a number of httpModules available to provide URL Rewriting or you can relatively easily write your own. As time was an issue in my case and I wanted something reliable I used UrlRewriter.net (
http://urlrewriter.net/). It is very easy to implement and if you are good with Regular Expressions you have all the flexibility you need.
In my case I simply wanted to my article links to display as "http://mywebsite.com/ARTICLE_TITLE_ID.aspx" instead of "http://mywebsite.com?ShowArticle?ID=71"
First I downloaded the binary from the above site and added Intelligencia.UrlRewriter.dll to the "bin" directory of my site.
Next I made the following additions to my web.config:
Between <configSections> & </configSections>
Code:
<section name="rewriter"
requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
Between <httpModules> and </httpModules>
Code:
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
Finally I added my rewriter expressions (anywhere in root of <configSections>):
Code:
<rewriter>
<rewrite url="~/([A-Za-z0-9-].+)_([0-9]+).aspx$" to="~/ShowArticle.aspx?ID=$2"/>
</rewriter>
The ID of the article needs to be in the URL you are displaying somewhere so it can be passed back to the querystring. I would have liked to have my URL in the format:
http://mywebsite.com/ArticleID/ArticleTitle.aspx (i.e. .../71/Bits and Bobs.aspx) but I found that adding the extra "/" in my URL resulted in the pages not locating my .css file. Would be interesting to hear if anyone else has had this problem???
The regular expression above passes the number following the underscore "_([0-9]+)" as the querystring.
Once you have done this you can type in any text followed by an article to retrieve an article e.g.
http://mywebsite.com/AnyTextIWantHere_71.aspx.
Now I just needed to change the URL's of the hyperlinks created by the ArticleListing.ascx control. Something I noticed first of all is that I would need to strip out the spaces of my article titles otherwise you end up with html space characters "%20" in your URL.
I changed my link to the below:
Code:
<asp:HyperLink runat="server" ID="lnkTitle" CssClass="articletitle" Text='<%# Eval("Title") %>' NavigateUrl='<%# "~/" & Eval("Title").Replace(" ", "_") & "_" & Eval("ID") & ".aspx" %>' ToolTip='<%# Eval("Title") %>' />
It's not the tidiest way of creating the URL but it works for now.
So now my article with title "Super Industrial Widgets" now has a hyperlink pointing to:
http://mywebsite.com/Super_Industrial_Widgets_71.aspx
which is not only more likely to give you higher page rankings but looks much better than:
http://mywebsite.com/ShowArticle.aspx?ID=71
Hope this is of some use.
For those people who have already implemented URL rewriting it would be great to hear how your methods.
Thanks,
Retro