URL rewriting in Blog Engine.NET

5. June 2010 14:47

BlogEngine.NET  6 Comments

I was just looking for a way to get short URL’s for my blog, I used some extensions, some URLrewriter.NET but still not able to get this work. So I drop an e-mail to Scott Hanselman and was waiting for his response. If you look at Scott’s blog you will see that he has very simple URL for his blog posts which eventually get his posts higher ranks on search engine indexing. What I have found so far is that if you have a simple URL the search engine will crawl that page during indexing and your page is on the top of the search results or if it is not on the top then it must be at least on the first page. Remember search engine crawlers will avoid crawling pages that do not have a simple URL, like if your page has a query string it won’t be get crawled by the search engine crawler.

The URLRewriter module in BlogEngine didn’t seems to be working for Posts. I want to have simple SEO friendly URLs like http://www.midnightprogrammer.net/post/Windows-7-Logon-Screen-Changer.aspx and not http://www.midnightprogrammer.net/post/2010/05/30/Windows-7-Logon-Screen-Changer.aspx But there is no way to do this until I hook into BlogEngine.Core.dll.

Open the whole solution in Visual Studio and open Post.cs file and navigate to the RelativeLink property in Post.cs file and change with the below code:

public string RelativeLink
{
	get
	{
		string slug = Utils.RemoveIllegalCharacters(Slug) + BlogSettings.Instance.FileExtension;
		if (BlogSettings.Instance.TimeStampPostLinks)
			return Utils.RelativeWebRoot + "post/" + slug;
		return Utils.RelativeWebRoot + "post/" + slug;
	}
}

Recompile your DLL and place in bin directory in your blogengine root folder. Now you will have short URLs which do not have any date stamp. Having short URLs for all your posts doesn’t affect the posts with old URLs that most of the people have bookmarked on their blogs or on social bookmarking sites. Hope this helps.

Currently rated 4.0 by 4 people

Comments (6)

Rahul kant Rahul kant
8/5/2010 11:34:11 PM #

Nice information. thanks

Cristian Cristian
11/4/2011 8:03:58 PM #

canging this http://localhost:52457/BlogEngine.NET/default.aspx in this ? http://localhost:52457/default.aspx thanks

Nabil Nabil
12/2/2011 11:13:08 PM #

I couldn't find the code you're referring to. Maybe they change it in the latest version? could you please help? Thanks, Nabil

Prashant Prashant
12/3/2011 12:05:21 PM #

@Nabil: Which version of BE you are using? I have this post when I was using 1.5.0 and the code was intact in BE 2.0 also. If you are using BE 2.0 then you will be able to find the above code.

nick nick
7/11/2012 3:42:23 AM #

thanks for this information!

Thomas Figueroa Thomas Figueroa
7/27/2016 9:00:26 AM #

Great information on url rewriting . We must always have SEO friendly urls so that there are high chances of our blogs or websites being noticed .

Add Comment

Visit blogadda.com to discover Indian blogs Computers Blogs