This project is read-only.

SeoFriendly URL / URL Rewriting

Topics: Business Logic Layer, Controls
Nov 28, 2011 at 8:15 PM

Hi to everyone,

i'm pretty new to blogengine, and i would like to know from more experienced user if in blogengine exists something to improve the Seo.

Basically what i would like to do is index my articles under their categories.

What happen now is that if i make an article (let's say "Basics of C Sharp") and i put it under the categories "Programming Tutorial"(Parent) --> "CSharp"(Child) the final url to my article will be:

Instead, what i would like to get is:

How can i achieve this result? Can anyone point me in the right direction?

Thank you very much in advance!




Nov 28, 2011 at 9:01 PM

One issue with your approach is that post can belong to multiple categories. I understand that you can self-restrict to one, but it won't work for all. Anyways, you can take a look at URL rewrite module, specifically at RewritePost method, to get an ideas and maybe find solution that works for you.

Nov 30, 2011 at 6:05 PM

Hi rtur,
 thank you very much for you opinion and suggestion.
I tried to understand the logic behind the Rewrite Post Method.
For my understanding it seems that the right post is found by the slug (my havedate is set to true so the 2 previous if are passed for this), after retrieving the right post, it simply redirect it to the post.aspx passing the id etc.
I ended up editing the post class in this way:

public string RelativeLink

                var theslug = Utils.RemoveIllegalCharacters(this.Slug) + BlogSettings.Instance.FileExtension;


                return BlogSettings.Instance.TimeStampPostLinks
                           ? string.Format(
                               this.DateCreated.ToString("yyyy/MM/dd/", CultureInfo.InvariantCulture),
                           : string.Format("{0}post/{2}/{1}", Utils.RelativeWebRoot, theslug,Categories[0].CompleteTitleForSEO());

basically i hardcoded the categories in the relative link.

Here the CompleteTitleForSeo() method:

public string CompleteTitleForSEO()
            return this.parent == null
                       ? this.title
                       : string.Format("{0}/{1}", GetCategory((Guid)this.parent).CompleteTitleForSEO(), this.title.Replace(" ","-"));

Keeping in mind that i'm going to add only one category for each post (only one direct, obviously this category is going to have a parent), do you think that this can bring up errors in the blogengine engine? (sorry for the pun)
At the moment it seems to work.

Thank you very much!



Nov 30, 2011 at 8:49 PM

I suppose it will work for your need, given you only have one category for the post and only go one level deep (single parent). Pretty restrictive, but if this is what you after - should work fine. Just don't forget that, if you going to upgrade later on, you'll need to carry over those changes which can become a pain overtime.

Nov 30, 2011 at 8:58 PM

I'll keep it in mind,

thank you very much for your opinion!



Mar 27, 2012 at 6:12 PM

Ale84 - did you have to change any code in the Urlrewrite.cs file in order for this to work?


I am also trying to include the category in post URLs and have not been able to find a solution that has worked for me, but hoping yours will.  It looks like you only changed the Post.cs file, is this correct? And did this work for you using BE 2.5?



Thank you in advance!!